UNPKG

rsshub

Version:
51 lines (50 loc) 1.54 kB
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs"; import { t as parseDate } from "./parse-date-CjhZE69i.mjs"; import { t as timezone } from "./timezone-DE--ze1V.mjs"; import { load } from "cheerio"; //#region lib/routes/gov/nanjing/index.ts const route = { path: "/:category", categories: ["government"], example: "/gov/nanjing/news", parameters: { category: "分类名" }, description: `| 南京信息 | 部门动态 | 各区动态 | 民生信息 | | :------: | :--------: | :------: | :--------: | | news | department | district | livelihood |`, name: "信息公开", maintainers: ["ocleo1"], handler }; const host = "https://www.nanjing.gov.cn"; const categories = /* @__PURE__ */ new Map([ ["news", "njxx"], ["department", "bmdt"], ["district", "gqdt"], ["livelihood", "msxx"] ]); async function handler(ctx) { const { category } = ctx.req.param(); const path = categories.get(category); if (!path) throw new Error("Cannot find page"); const link = `${host}/${path}/`; const $ = load(await rofetch(`${link}index.html`)); const items = $(".center ul li").toArray().map((item) => { const $item = $(item); const $aTag = $item.find("a"); return { title: $aTag.text(), description: $aTag.attr("title"), pubDate: timezone(parseDate($item.find("span").text()), 8), link: new URL($aTag.attr("href"), link).href }; }); const title = $(".zxft_title span").text(); return { title, link, description: `${title} - ${$("head title").text()}`, item: items }; } //#endregion export { route };