UNPKG

rsshub

Version:
41 lines (40 loc) 1.22 kB
import { t as rofetch } from "./ofetch-U0CdpE2g.mjs"; import { t as parseDate } from "./parse-date-3kcy2Eau.mjs"; import { t as cache_default } from "./cache-C1Y-9qDV.mjs"; import { load } from "cheerio"; //#region lib/routes/cgtn/opinions.ts const route = { path: "/opinions", categories: ["new-media"], example: "/cgtn/opinions", name: "Opinions", maintainers: ["nczitzk"], handler }; async function handler() { const rootUrl = "https://www.cgtn.com/opinions"; const response = await rofetch(rootUrl); const $ = load(response); $(".cg-pic").parent().remove(); const list = $(".cg-title h3").toArray().slice(0, 15).map((item) => { const a = $(item).find("a"); return { title: a.text(), link: a.attr("href"), pubDate: parseDate(Number.parseInt(a.attr("data-time"))) }; }); return { title: "CGTN - Opinions", link: rootUrl, item: await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => { const detailResponse = await rofetch(item.link); const content = load(detailResponse); item.author = content(".news-author-name").text(); item.description = content("#cmsMainContent").html() ?? void 0; return item; }))) }; } //#endregion export { route };