UNPKG

rsshub

Version:
89 lines (84 loc) 3.93 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/ycwb/index.ts init_esm_shims(); const route = { path: "/:node", categories: ["traditional-media"], example: "/ycwb/1", parameters: { node: "栏目 id" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, name: "新闻", maintainers: ["TimWu007"], handler, description: `注:小部分栏目的 URL 会给出 nodeid。如未给出,可打开某条新闻链接后,查看网页源代码,搜索 nodeid 的值。 常用栏目节点: | 首页 | 中国 | 国际 | 体育 | 要闻 | 珠江评论 | 民生观察 | 房产 | 金羊教育 | 金羊财富 | 金羊文化 | 金羊健康 | 金羊汽车 | | ---- | ---- | ---- | ---- | ---- | -------- | -------- | ---- | -------- | -------- | -------- | -------- | -------- | | 1 | 14 | 15 | 16 | 22 | 1875 | 21773 | 222 | 5725 | 633 | 5281 | 21692 | 223 | | 广州 | 广州 - 广州要闻 | 广州 - 社会百态 | 广州 - 深读广州 | 广州 - 生活服务 | 今日大湾区 | 广东 - 政经热闻 | 广东 - 民生视点 | 广东 - 滚动新闻 | | ---- | --------------- | --------------- | --------------- | --------------- | ---------- | --------------- | --------------- | --------------- | | 18 | 5261 | 6030 | 13352 | 83422 | 100418 | 13074 | 12252 | 12212 |` }; async function handler(ctx) { const { data: response } = await got_default(`https://6api.ycwb.com/app_if/jy/getArticles?nodeid=${ctx.req.param("node") ?? 1}&pagesize=15`); const list = response.artiles.map((item) => ({ title: item.TITLE, description: art(path.join(__dirname, "templates/description-6615c3d4.art"), { thumb: item.PICLINKS, description: item.ABSTRACT }), pubDate: timezone(parseDate(item.PUBTIME), 8), link: item.PUBURL, nodeName: item.NODENAME })); let nodeName = ""; let nodeLink = ""; const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => { const content = load((await got_default({ method: "get", url: item.link })).data); content(".main_article").contents().filter(function() { return this.nodeType === 8; }).each(function() { if (/audioPlayer|audio-box/.test(this.data)) this.data = ""; if (/author/.test(this.data)) item.author = this.data.split("<author>")[1].split("</author>")[0]; }); nodeName = nodeName === "" ? item.nodeName : nodeName; const children = content(".path").children("a"); for (const child of children) if (content(child).text() === nodeName && nodeLink === "") nodeLink = content(child).attr("href"); content("span").removeAttr("style").removeAttr("class"); content("img").removeAttr("style").removeAttr("class").removeAttr("placement").removeAttr("data-toggle").removeAttr("trigger").removeAttr("referrerpolicy"); content("br").removeAttr("style").removeAttr("class"); content("p").removeAttr("style").removeAttr("class"); content(".space10, .ddf").remove(); item.description += content(".main_article").html() ?? ""; return item; }))); return { title: `羊城晚报金羊网 - ${nodeName}`, link: String(nodeLink === "" ? "https://www.ycwb.com/" : nodeLink), item: items }; } //#endregion export { route };