UNPKG

rsshub

Version:
86 lines (84 loc) 2.81 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 { 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/news/xhsxw.ts init_esm_shims(); const route = { path: ["/xhsxw", "/whxw"], categories: ["new-media"], example: "/news/xhsxw", parameters: {}, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["news.cn/xhsxw.htm"] }], name: "新华社新闻", maintainers: ["nczitzk"], handler, url: "news.cn/xhsxw.htm" }; async function handler(ctx) { const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit"), 10) : 100; const rootUrl = "http://www.news.cn"; const currentUrl = new URL("xhsxw.htm", rootUrl).href; const { data: currentResponse } = await got_default(currentUrl); const $ = load(currentResponse); const id = $("ul.wz-list").prop("data").replace(/datasource:/, ""); const apiUrl = new URL(`ds_${id}.json`, rootUrl).href; const { data: { datasource: response } } = await got_default(apiUrl); let items = response.slice(0, limit).map((item) => ({ title: item.title, link: new URL(item.publishUrl, rootUrl).href, description: art(path.join(__dirname, "templates/description-881baa33.art"), { images: item.shareImages?.map((i) => ({ src: i.imageUrl, alt: item.title })) ?? void 0, intro: item.summary }), author: item.author, category: item.keywords.split(/-|,/), guid: `news-${item.contentId}`, pubDate: timezone(parseDate(item.publishTime), 8) })); items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => { try { const { data: detailResponse } = await got_default(item.link); const content = load(detailResponse); item.description += art(path.join(__dirname, "templates/description-881baa33.art"), { description: content("#detailContent").html() }); } catch {} return item; }))); const title = $("title").text(); const image = new URL("20141223_xhsxw_logo_v1.png", rootUrl).href; const icon = new URL("favicon.ico", rootUrl).href; return { item: items, title, link: currentUrl, description: title.split(/_/)[0], language: "zh", image, icon, logo: icon, author: title.split(/_/).pop(), allowEmpty: true }; } //#endregion export { route };