UNPKG

rsshub

Version:
57 lines (56 loc) 1.71 kB
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs"; import { t as parseDate } from "./parse-date-CjhZE69i.mjs"; import { t as cache_default } from "./cache-CiDoUSLo.mjs"; import { t as InvalidParameterError } from "./invalid-parameter-CGxhjomn.mjs"; import { load } from "cheerio"; //#region lib/routes/gov/wuhan/kjj.ts const route = { path: "/kjj/:caty", categories: ["government"], example: "/gov/wuhan/kjj/tzgg", parameters: { caty: "类别" }, name: "武汉市科学技术局 - 新闻中心", maintainers: ["tudou027"], handler, description: `| 通知公告 | 公示信息 | | :------: | :------: | | tzgg | gsxx |` }; const rootUrl = "https://kjj.wuhan.gov.cn/"; const config = { tzgg: { link: "/wmfw/tzgg/tzgg_18371/", title: "通知公告" }, gsxx: { link: "/wmfw/tzgg/gsxx/", title: "公示信息" } }; async function handler(ctx) { const { caty } = ctx.req.param(); const cfg = config[caty]; if (!cfg) throw new InvalidParameterError("Bad category. See docs"); const currentUrl = new URL(cfg.link, rootUrl).href; const $ = load(await rofetch(currentUrl)); const list = $("div.list_news li").slice(0, 20).toArray().map((item) => { const $item = $(item); const a = $item.find("a[href]"); return { title: a.text(), link: new URL(a.attr("href"), currentUrl).href, pubDate: parseDate($item.find("span").text(), "YYYY-MM-DD") }; }); const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => { item.description = load(await rofetch(item.link))("div.art_content").html(); return item; }))); return { title: `武汉科技局 - ${cfg.title}`, link: rootUrl, item: items }; } //#endregion export { route };