UNPKG

rsshub

Version:
72 lines (71 loc) 2.49 kB
import { t as parseDate } from "./parse-date-Cr0wQjV_.mjs"; import { t as cache_default } from "./cache-BkqOokyU.mjs"; import { t as got_default } from "./got-BTowW50G.mjs"; import { load } from "cheerio"; //#region lib/routes/gov/mem/sgcc.ts const route = { path: "/gk/sgcc/:category?", categories: ["government"], example: "/gov/mem/gk/sgcc/tbzdsgdcbg", parameters: { category: "分类,见下表,默认为挂牌督办" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["www.mem.gov.cn/gk/sgcc/:category"], target: "/gk/sgcc/:category" }], name: "事故及灾害查处", maintainers: ["nczitzk"], handler, description: `| 挂牌督办 | 调查报告 | | -------- | ---------- | | sggpdbqk | tbzdsgdcbg |` }; async function handler(ctx) { const { category = "sggpdbqk" } = ctx.req.param(); const limit = ctx.req.query("limit") ? Number(ctx.req.query("limit")) : 30; const rootUrl = "https://www.mem.gov.cn"; const currentUrl = new URL(`gk/sgcc/${category}`, rootUrl).href; const { data: response } = await got_default(currentUrl); const $ = load(response); let items = $("table.center_main02").find("a[title]").slice(0, limit).toArray().map((item) => { const $item = $(item); const regExp = new RegExp(String.raw`\/sgcc\/${category}\/\.\.\.`); const link = new URL(`${category}/${$item.prop("href").replace(/\.\//, "")}`, currentUrl).href.replace(regExp, ""); return { title: $item.contents().first().text(), link, pubDate: parseDate($item.find("span").text()), enclosure_url: link, enclosure_type: `application/${link.split(/\./).pop()}` }; }); items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => { if (item.link.endsWith("html")) { const { data: detailResponse } = await got_default(item.link); item.description = load(detailResponse)("#content").html(); } return item; }))); const icon = new URL($("link[rel=\"shortcut icon\"]").prop("href"), rootUrl).href; return { item: items, title: $("title").text(), link: currentUrl, description: $("meta[name=\"ColumnDescription\"]").prop("content"), language: "zh", image: new URL($("#imag").prop("src"), rootUrl).href, icon, logo: icon, subtitle: $("meta[name=\"ColumnName\"]").prop("content"), author: $("meta[name=\"SiteName\"]").prop("content") }; } //#endregion export { route };