UNPKG

rsshub

Version:
74 lines (72 loc) 2.17 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 cache_default } from "./cache-Bo__VnGm.mjs"; import "./helpers-DxBp0Pty.mjs"; import { t as got_default } from "./got-KxxWdaxq.mjs"; import { load } from "cheerio"; //#region lib/routes/cbc/topics.ts const route = { path: "/topics/:topic?", categories: ["traditional-media"], example: "/cbc/topics", parameters: { topic: "Channel,`Top Stories` by default. For secondary channel like `canada/toronto`, use `-` to replace `/`" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["cbc.ca/news"], target: "/topics" }], name: "News", maintainers: ["wb14123"], handler, url: "cbc.ca/news" }; async function handler(ctx) { const baseUrl = "https://www.cbc.ca"; const topic = ctx.req.param("topic") || ""; const url = `${baseUrl}/news${topic ? `/${topic.replace("-", "/")}` : ""}`; const data = (await got_default(url)).data; const $ = load(data); const links = []; function pushLinks(index, item) { const link = item.attribs.href; if (link.startsWith("/")) links.push(baseUrl + link); } $("a.contentWrapper").each(pushLinks); $("a.card").each(pushLinks); const out = await Promise.all(links.map((link) => cache_default.tryGet(link, async () => { const $$1 = load((await got_default(link)).data); const head = JSON.parse($$1("script[type=\"application/ld+json\"]").first().text()); if (!head) return []; const title = head.headline; let author = ""; if (head.author) author = head.author.map((author$1) => author$1.name).join(" & "); const pubDate = head.datePublished; const descriptionDom = $$1("div[data-cy=storyWrapper]"); descriptionDom.find("div[class=share]").remove(); const description = descriptionDom.html(); return { title, author, pubDate, description, link }; }))); return { title: $("title").text(), link: url, item: out.filter((x) => x.title) }; } //#endregion export { route };