UNPKG

rsshub

Version:
63 lines (61 loc) 2.17 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 { r as getSubPath } from "./common-utils-vrWQFAEk.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 { load } from "cheerio"; //#region lib/routes/gov/cmse/index.ts init_esm_shims(); const route = { path: "/cmse/*", name: "Unknown", maintainers: [], handler }; async function handler(ctx) { const path = getSubPath(ctx).replaceAll(/(^\/cmse|\/$)/g, ""); const currentUrl = `http://www.cmse.gov.cn${path === "" ? "/xwzx/zhxw/" : `${path}/`}`; const $ = load((await got_default({ method: "get", url: currentUrl })).data); let items = $("#list li a").slice(0, ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit")) : 15).toArray().map((item) => { item = $(item); const pubDate = item.next().text(); const link = new URL(item.attr("href"), currentUrl).href; return { title: item.text(), pubDate: parseDate(pubDate), link: /\.html$/.test(link) ? link : `${link}#${pubDate}` }; }); items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => { const detailResponse = await got_default({ method: "get", url: item.link }); const content = load(detailResponse.data); content(".share").remove(); const detailPubTimeMatches = detailResponse.data.match(/__\$pubtime='(.*?)';var/); item.pubDate = detailPubTimeMatches ? timezone(parseDate(detailPubTimeMatches[1]), 8) : item.pubDate; item.description = art(path.join(__dirname, "templates/description-f9ed8f8b.art"), { video: content("#con_video").html(), description: content(".TRS_Editor, #content").html() }); return item; }))); return { title: $("title").text(), link: currentUrl, item: items }; } //#endregion export { route };