UNPKG

rsshub

Version:
64 lines (62 loc) 2.42 kB
import "./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 { t as got_default } from "./got-KxxWdaxq.mjs"; import { load } from "cheerio"; import pMap from "p-map"; //#region lib/routes/cts/news.ts const route = { path: "/:category", categories: ["traditional-media"], example: "/cts/real", parameters: { category: "类别" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: true, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["news.cts.com.tw/:category/index.html"] }], name: "新聞", maintainers: ["miles170"], handler, description: `| 即時 | 氣象 | 政治 | 國際 | 社會 | 運動 | 生活 | 財經 | 台語 | 地方 | 產業 | 綜合 | 藝文 | 娛樂 | | ---- | ------- | -------- | ------------- | ------- | ------ | ---- | ----- | --------- | ----- | ---- | ------- | ---- | --------- | | real | weather | politics | international | society | sports | life | money | taiwanese | local | pr | general | arts | entertain |` }; async function handler(ctx) { const currentUrl = `https://news.cts.com.tw/${ctx.req.param("category")}/index.html`; const $ = load((await got_default(currentUrl)).data); const items = await pMap($("#newslist-top a[title]").slice(0, ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit")) : 20), (item) => { item = $(item); const link = item.attr("href"); return cache_default.tryGet(link, async () => { const $$1 = load((await got_default(link)).data); const author = $$1(".artical-content p:eq(0)").text().trim(); $$1(".artical-content p:eq(0), .artical-content .flexbox").remove(); return { title: item.attr("title"), author, description: $$1(".artical-content").html(), category: $$1("meta[property=\"article:section\"]").attr("content"), pubDate: parseDate($$1("meta[property=\"article:published_time\"]").attr("content")), link }; }); }, { concurrency: 5 }); return { title: $("title").text(), link: currentUrl, description: $("meta[name=\"description\"]").attr("content"), item: items }; } //#endregion export { route };