UNPKG

rsshub

Version:
46 lines (44 loc) 1.6 kB
import "./esm-shims-CzJ_djXG.mjs"; import "./config-C37vj7VH.mjs"; import "./dist-BInvbO1W.mjs"; import "./logger-Czu8UMNd.mjs"; import { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs"; import { t as parseDate } from "./parse-date-BrP7mxXf.mjs"; import { t as cache_default } from "./cache-Bo__VnGm.mjs"; import { load } from "cheerio"; //#region lib/routes/ftm/index.ts const route = { path: "/", categories: ["new-media"], example: "/ftm", parameters: {}, name: "文章", maintainers: ["dzx-dzx"], radar: [{ source: ["www.ftm.eu"] }], handler }; async function handler(ctx) { const currentUrl = `https://www.ftm.eu/articles`; const $ = load(await ofetch_default(currentUrl)); const list = $(".article-card").toArray().map((e) => ({ link: $(e).attr("href"), title: $(e).find("h2").text() })).slice(0, ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit"), 10) : Infinity); const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => { const content = load(await ofetch_default(item.link)); const ldjson = JSON.parse(content("[type=\"application/ld+json\"]:not([data-schema])").text()); item.pubDate = parseDate(ldjson.datePublished); item.updated = parseDate(ldjson.dateModified); item.author = content("[name='author']").toArray().map((e) => ({ name: $(e).attr("content") })); item.category = content(".collection .tab").text().trim() || null; item.description = content(".body").html(); return item; }))); return { title: $("title").text(), link: currentUrl, item: items }; } //#endregion export { route };