UNPKG

rsshub

Version:
60 lines (58 loc) 2.19 kB
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs"; import "./config-C37vj7VH.mjs"; import "./dist-BInvbO1W.mjs"; import "./logger-Czu8UMNd.mjs"; import "./ofetch-BIyrKU3Y.mjs"; import { t as parseDate } from "./parse-date-BrP7mxXf.mjs"; import { t as cache_default } from "./cache-Bo__VnGm.mjs"; import "./helpers-DxBp0Pty.mjs"; import { r as getSubPath } from "./common-utils-vrWQFAEk.mjs"; import { t as art } from "./render-BQo6B4tL.mjs"; import { t as got_default } from "./got-KxxWdaxq.mjs"; import { t as timezone } from "./timezone-D8cuwzTY.mjs"; import path from "node:path"; import { load } from "cheerio"; //#region lib/routes/pts/index.ts init_esm_shims(); const route = { path: "*", name: "Unknown", maintainers: [], handler }; async function handler(ctx) { const currentUrl = `https://news.pts.org.tw${getSubPath(ctx) === "/" ? "/dailynews" : getSubPath(ctx)}`; const $ = load((await got_default({ method: "get", url: currentUrl })).data); let items = $("h1 a,h2 a").slice(0, ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit")) : 30).toArray().map((item) => { item = $(item); return { title: item.text(), link: item.attr("href") }; }); items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => { const content = load((await got_default({ method: "get", url: item.link })).data); item.author = content(".reporter-container a").toArray().map((e) => ({ name: content(e).text() })); item.pubDate = timezone(parseDate(content(".article-time .mr-2 time").text()), 8); item.updated = timezone(parseDate(content(".article-time span:nth-child(2) time").text()), 8); item.category = content(".tag-list").first().find(".blue-tag").toArray().map((t) => content(t).text()).filter((t) => t !== "..."); item.description = art(path.join(__dirname, "templates/description-33e81d41.art"), { image: content("meta[property=\"og:image\"]").attr("content"), description: content(".post-article").html() }); return item; }))); return { title: $("title").text().replace(/第\d+頁 | /, ""), link: currentUrl, item: items }; } //#endregion export { route };