UNPKG

rsshub

Version:
43 lines (42 loc) 1.41 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 { t as timezone } from "./timezone-UiMFOuvL.mjs"; import { load } from "cheerio"; //#region lib/routes/gov/nppa/channels.ts const route = { path: "/:path{.+}", name: "通用", example: "/gov/nppa/xxfb/ywxx", parameters: { path: "路径,留空默认 `xxfb/ywxx`" }, maintainers: ["y2361547758"], handler }; const host = "https://www.nppa.gov.cn"; async function handler(ctx) { const { path = "xxfb/ywxx" } = ctx.req.param(); const link = `${host}/${path}/`; const response = await rofetch(link); const $ = load(response); const list = $(".m2nRcon li").toArray().map((item) => { const $item = $(item); const a = $item.find("a"); return { link: new URL(a.attr("href"), link).href, pubDate: timezone(parseDate($item.find("span").text().replaceAll(/[[\]]/g, "")), 8) }; }); return { title: `国家新闻出版署 - ${$(".m2nRt").text().trim()}`, link, item: await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => { const response = await rofetch(item.link); const $ = load(response); item.title = $(".m3page_t").text().trim() || $("head title").text(); item.description = $(".m3pageEdit").html(); return item; }))) }; } //#endregion export { route };