UNPKG

rsshub

Version:
120 lines (118 loc) 4.27 kB
import "./esm-shims-CzJ_djXG.mjs"; import "./config-C37vj7VH.mjs"; import "./dist-BInvbO1W.mjs"; import { t as logger_default } from "./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 { t as timezone } from "./timezone-D8cuwzTY.mjs"; import { load } from "cheerio"; //#region lib/routes/gov/cn/news/index.ts const route = { path: "/cn/news/:uid", categories: ["government"], example: "/gov/cn/news/bm", parameters: { uid: "分类名" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, name: "政府新闻", maintainers: ["EsuRt", "howfool"], handler, description: `| 政务部门 | 滚动新闻 | 新闻要闻 | 国务院新闻 | 国务院工作会议 | 政策文件 | | :------: | :------: | :------: | :--------: | :------------: | :------: | | bm | gd | yw | gwy | gwyzzjg | zhengce |` }; async function handler(ctx) { const uid = ctx.req.param("uid"); const originDomain = "https://www.gov.cn"; let url = ""; let title = ""; let list = ""; switch (uid) { case "bm": url = `${originDomain}/lianbo/bumen/index.htm`; title = "中国政府网 - 部门政务"; break; case "yw": url = `${originDomain}/yaowen/index.htm`; title = "中国政府网 - 新闻要闻"; break; case "gd": url = `${originDomain}/yaowen/index.htm`; title = "中国政府网 - 滚动新闻"; break; case "gwy": url = `${originDomain}/pushinfo/v150203/`; title = "中国政府网 - 国务院信息"; break; case "zhengce": url = "http://sousuo.gov.cn/s.htm?t=zhengcelibrary"; title = "中国政府网 - 政策文件"; break; case "gwyzzjg": url = `${originDomain}/gwyzzjg/huiyi/`; title = "中国政府网 - 国务院工作会议"; break; default: logger_default.error("pattern not matched"); } const $ = load((await got_default.get(url)).data); if (url.includes("zhengcelibrary")) list = $(".dys_middle_result_content_item"); else if (url.includes("bumen")) list = $(".infolist li"); else list = $(".news_box .list li:not(.line)"); return { title, link: url, item: await Promise.all(list.toArray().map((item) => { item = $(item); let contentUrl = item.find("a").attr("href"); contentUrl = contentUrl.startsWith("http") ? contentUrl : new URL(contentUrl, url).href; return cache_default.tryGet(contentUrl, async () => { let description; let fullTextData; let fullTextGet; let pubDate; let author; let category; if (/dysMiddleResultConItemTitle/g.test(item.html())) if (contentUrl.includes("content")) { fullTextGet = await got_default.get(contentUrl); fullTextData = load(fullTextGet.data); fullTextData(".shuzi").remove(); fullTextData("#myFlash").remove(); description = /pages_content/g.test(fullTextData.html()) ? fullTextData(".pages_content").html() : fullTextData("#UCAP-CONTENT").html(); } else description = item.find("a").text(); else if (contentUrl.includes("content")) { fullTextGet = await got_default.get(contentUrl); fullTextData = load(fullTextGet.data); const $1 = fullTextData.html(); pubDate = timezone(parseDate(fullTextData("meta[name=\"firstpublishedtime\"]").attr("content"), "YYYY-MM-DD HH:mm:ss"), 8); author = fullTextData("meta[name=\"author\"]").attr("content"); category = fullTextData("meta[name=\"keywords\"]").attr("content").split(/[,;]/); if (/zhengceku/g.test(contentUrl)) description = fullTextData(".pages_content").html(); else { fullTextData(".shuzi").remove(); fullTextData("#myFlash").remove(); description = /UCAP-CONTENT/g.test($1) ? fullTextData("#UCAP-CONTENT").html() : fullTextData("body").html(); } } else description = item.find("a").text(); return { title: item.find("a").text(), description, link: contentUrl, pubDate, author, category: category.filter(Boolean) }; }); })) }; } //#endregion export { route };