UNPKG

rsshub

Version:
55 lines (53 loc) 1.66 kB
import "./dist-Bog6z_OM.mjs"; import "./config-MQ-7ebJ_.mjs"; import "./logger-C4avouvV.mjs"; import "./ofetch-DKl_Ma9g.mjs"; import { t as parseDate } from "./parse-date-r5WDWHno.mjs"; import "./is-worker-DESPicPc.mjs"; import { t as cache_default } from "./cache-SV6W5EPy.mjs"; import "./helpers-Bo4JQYdN.mjs"; import { t as got_default } from "./got-CO-ndVl2.mjs"; import { load } from "cheerio"; //#region lib/routes/nielsberglund/index.ts const route = { path: "/blog", categories: ["blog"], example: "/nielsberglund/blog", radar: [{ source: ["nielsberglund.com/"] }], url: "nielsberglund.com/", name: "Blog", maintainers: ["liyaozhong"], handler, description: "Niels Berglund Blog Posts" }; async function handler() { const rootUrl = "https://nielsberglund.com"; const $ = load((await got_default(rootUrl)).data); let items = $(".post-preview").toArray().map((item) => { const $item = $(item); const href = $item.find("a").first().attr("href"); const title = $item.find(".post-title").first().text().trim(); const dateStr = $item.find(".post-meta").text().trim(); if (!href || !title) return null; return { title, link: new URL(href, rootUrl).href, pubDate: parseDate(dateStr) }; }).filter((item) => item !== null); items = (await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => { try { item.description = load((await got_default(item.link)).data)(".post-container").html() || ""; return item; } catch { return item; } })))).filter((item) => item !== null); return { title: "Niels Berglund Blog", link: rootUrl, item: items }; } //#endregion export { route };