UNPKG

rsshub

Version:
61 lines (59 loc) 2.06 kB
import "./esm-shims-CzJ_djXG.mjs"; import { t as config } from "./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 got_default } from "./got-KxxWdaxq.mjs"; import { t as timezone } from "./timezone-D8cuwzTY.mjs"; import { n as finishArticleItem } from "./wechat-mp-Dq_pp853.mjs"; import { load } from "cheerio"; //#region lib/routes/gov/nmpa/generic.ts const baseUrl = "https://www.nmpa.gov.cn"; const route = { path: "/nmpa/*", name: "Unknown", maintainers: [], handler }; async function handler(ctx) { const path = ctx.params[0]; const url = `${baseUrl}/${path.endsWith("/") ? path.slice(0, -1) : path}/index.html`; const data = await cache_default.tryGet(url, async () => { const { data: html } = await got_default(url); const $ = load(html); return { title: $("head title").text(), description: $("meta[name=ColumnDescription]").attr("content"), items: $(".list ul li").toArray().map((item) => { item = $(item); return { title: item.find("a").text().trim(), link: new URL(item.find("a").attr("href"), baseUrl).href, pubDate: parseDate(item.find("span").text(), "YYYY-MM-DD") }; }) }; }, config.cache.routeExpire, false); const items = await Promise.all(data.items.map((item) => { if (/^https:\/\/www\.nmpa\.gov\.cn\//.test(item.link)) return cache_default.tryGet(item.link, async () => { const { data: html } = await got_default(item.link); const $ = load(html); item.description = $(".text").html(); item.pubDate = timezone(parseDate($("meta[name=\"PubDate\"]").attr("content")), 8); return item; }); else if (/^https:\/\/mp\.weixin\.qq\.com\//.test(item.link)) return finishArticleItem(item); else return item; })); return { title: data.title, description: data.description, link: url, item: items }; } //#endregion export { route };