UNPKG

rsshub

Version:
60 lines (58 loc) 1.96 kB
import "./dist-Bog6z_OM.mjs"; import "./config-MQ-7ebJ_.mjs"; import "./logger-C4avouvV.mjs"; import { t as ofetch_default } from "./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 { r as getSubPath } from "./common-utils-Cz5bFBus.mjs"; import { t as timezone } from "./timezone-CA9Huotp.mjs"; //#region lib/routes/gov/beijing/bphc/index.ts const mapping = { "/project": { title: "项目介绍", list: "/front/index/project/page", detail: "/front/index/project", link: "/#/communityDetail?id=" }, "/announcement": { title: "通知公告", list: "/front/announcement/page", detail: "/front/announcement/", link: "/#/announcementList/detail?id=" } }; const route = { path: "/beijing/bphc/*", name: "Unknown", maintainers: [], handler }; async function handler(ctx) { const rootUrl = "https://gycpt.bphc.com.cn"; const defaultPath = "announcement"; const pathname = getSubPath(ctx).replaceAll(/(^\/beijing\/bphc|\/$)/g, ""); const obj = mapping[pathname === "" ? defaultPath : pathname.endsWith("/") ? pathname.slice(0, -1) : pathname]; const list = (await ofetch_default(`${rootUrl}${obj.list}`)).data?.records ?? []; const items = await Promise.all(list.map((item) => { const detail = `${rootUrl}${obj.detail}/${item.id}`; return cache_default.tryGet(detail, async () => { const detailResponse = await ofetch_default(detail); const description = (detailResponse.data?.content || detailResponse.data?.introduction) ?? ""; return { title: item.title || item.fullName, author: description.match(/来源:(.*?)</)?.[1].trim() ?? item.operator, link: `${rootUrl}${obj.link}${item.id}`, description, pubDate: timezone(parseDate(item.createTime), 8) }; }); })); return { title: obj.title, link: rootUrl, item: items }; } //#endregion export { route };