UNPKG

rsshub

Version:
57 lines (55 loc) 1.81 kB
import "./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 { r as getSubPath } from "./common-utils-vrWQFAEk.mjs"; import { t as got_default } from "./got-KxxWdaxq.mjs"; import { t as timezone } from "./timezone-D8cuwzTY.mjs"; import { load } from "cheerio"; import iconv from "iconv-lite"; //#region lib/routes/gov/nopss/index.ts const route = { path: "/nopss/*", name: "Unknown", maintainers: [], handler }; async function handler(ctx) { const params = getSubPath(ctx) === "/nopss" ? "/GB/219469" : getSubPath(ctx).replace(/^\/nopss/, ""); const rootUrl = "http://www.nopss.gov.cn"; const currentUrl = `${rootUrl}${params}`; const response = await got_default({ method: "get", url: currentUrl, responseType: "buffer" }); const $ = load(iconv.decode(response.data, "gbk")); let items = $(".p2j_list_con .clearfix li a").slice(0, ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit")) : 40).toArray().map((item) => { item = $(item); return { title: item.text(), link: `${rootUrl}${item.attr("href")}`, pubDate: timezone(parseDate(item.next().text(), "[YYYY-MM-DD HH:mm]"), 8) }; }); items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => { const detailResponse = await got_default({ method: "get", url: item.link, responseType: "buffer" }); item.description = load(iconv.decode(detailResponse.data, "gbk"))(".text_con").html(); return item; }))); return { title: $("title").text(), link: currentUrl, item: items }; } //#endregion export { route };