UNPKG

rsshub

Version:
52 lines (51 loc) 1.57 kB
import { t as rofetch } from "./ofetch-U0CdpE2g.mjs"; import { t as parseDate } from "./parse-date-3kcy2Eau.mjs"; import { t as timezone } from "./timezone-UiMFOuvL.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 response = await rofetch(`${link}index.html`); const $ = load(response); 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 };