UNPKG

rsshub

Version:
58 lines (56 loc) 1.88 kB
import "./dist-Bog6z_OM.mjs"; import "./config-MQ-7ebJ_.mjs"; import "./logger-C4avouvV.mjs"; import "./ofetch-DKl_Ma9g.mjs"; import { t as parseDate } from "./parse-date-r5WDWHno.mjs"; import "./is-worker-DESPicPc.mjs"; import { t as cache_default } from "./cache-SV6W5EPy.mjs"; import "./helpers-Bo4JQYdN.mjs"; import { r as getSubPath } from "./common-utils-Cz5bFBus.mjs"; import { t as got_default } from "./got-CO-ndVl2.mjs"; import { t as timezone } from "./timezone-CA9Huotp.mjs"; import { load } from "cheerio"; //#region lib/routes/gov/sh/yjj/index.ts const route = { path: ["/sh/yjj/*", "/shanghai/yjj/*"], name: "Unknown", maintainers: [], handler }; async function handler(ctx) { const params = getSubPath(ctx) === "/sh/yjj" ? "/sh/yjj/zx-ylqx" : getSubPath(ctx); const rootUrl = "https://yjj.sh.gov.cn"; const currentUrl = `${rootUrl}${params.replace(/^\/sh\/yjj/, "")}/index.html`; const $ = load((await got_default({ method: "get", url: currentUrl })).data); let items = $(".pageList li a").toArray().map((item) => { item = $(item); const link = item.attr("href"); return { title: item.text(), pubDate: parseDate(item.next().text()), link: link.startsWith("http") ? link : `${rootUrl}${link}` }; }); items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => { try { const content = load((await got_default({ method: "get", url: item.link })).data); const pubDate = content("meta[name=\"pubdate\"]").attr("content") || content("meta[name=\"PubDate\"]").attr("content"); item.description = content("#ivs_content").html(); item.pubDate = timezone(parseDate(pubDate, ["YYYY-MM-DD HH:mm:ss", "YYYY-MM-DD HH:mm"]), 8); } catch {} return item; }))); return { title: $("title").text().replace(/--/, " - "), link: currentUrl, item: items }; } //#endregion export { route };