UNPKG

rsshub

Version:
131 lines (128 loc) 4.83 kB
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs"; import "./config-C37vj7VH.mjs"; import "./dist-BInvbO1W.mjs"; import "./logger-Czu8UMNd.mjs"; import "./ofetch-BIyrKU3Y.mjs"; import { t as parseDate } from "./parse-date-BrP7mxXf.mjs"; import { t as cache_default } from "./cache-Bo__VnGm.mjs"; import "./helpers-DxBp0Pty.mjs"; import { t as art } from "./render-BQo6B4tL.mjs"; import { t as got_default } from "./got-KxxWdaxq.mjs"; import { t as timezone } from "./timezone-D8cuwzTY.mjs"; import path from "node:path"; import { load } from "cheerio"; //#region lib/routes/gov/sh/fgw/index.ts init_esm_shims(); const handler = async (ctx) => { const { category = "fgw_zxxxgk" } = ctx.req.param(); const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit"), 10) : 20; const rootUrl = "https://fgw.sh.gov.cn"; const currentUrl = new URL(`${category}/index.html`, rootUrl).href; const { data: response } = await got_default(currentUrl); const $ = load(response); const language = $("html").prop("lang"); let items = $("ul.nowrapli li").slice(0, limit).toArray().map((item) => { item = $(item); return { title: item.find("a").prop("title"), pubDate: parseDate(item.find("span.time").text()), link: new URL(item.find("a").prop("href"), rootUrl).href, language }; }); items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => { if (!item.link.endsWith(".html")) { item.enclosure_url = item.link; item.enclosure_type = item.link ? `application/${item.link.split(/\./).pop()}` : void 0; item.enclosure_title = item.title; return item; } const { data: detailResponse } = await got_default(item.link); const $$ = load(detailResponse); const title = $$("meta[name=\"ArticleTitle\"]").prop("content"); const image$1 = $$("div.pdf-content img").first().prop("src"); const description = art(path.join(__dirname, "templates/description-16be3a2a.art"), { images: image$1 ? [{ src: image$1, alt: title }] : void 0, description: $$("div#ivs_content").html() }); item.title = title; item.description = description; item.pubDate = timezone(parseDate($$("meta[name=\"PubDate\"]").prop("content")), 8); item.category = [...new Set([$$("meta[name=\"ColumnName\"]").prop("content"), $$("meta[name=\"ColumnKeywords\"]").prop("content")])].filter(Boolean); item.author = $$("meta[name=\"ContentSource\"]").prop("content"); item.content = { html: description, text: $$("div#ivs_content").text() }; item.image = image$1; item.banner = image$1; item.language = language; const enclosureUrl = $$("div.pdf-content a, div.xgfj a").first().prop("href"); item.enclosure_url = enclosureUrl ? new URL(enclosureUrl, rootUrl).href : void 0; item.enclosure_type = enclosureUrl ? `application/${enclosureUrl.split(/\./).pop()}` : void 0; item.enclosure_title = title; return item; }))); const author = $("meta[name=\"SiteName\"]").prop("content"); const image = $("span.logo-icon img").prop("src"); return { title: `${author} - ${$("meta[name=\"ColumnName\"]").prop("content")}`, description: $("meta[name=\"ColumnDescription\"]").prop("content"), link: currentUrl, item: items, allowEmpty: true, image, author, language }; }; const route = { path: ["/sh/fgw/:category{.+}?", "/shanghai/fgw/:category{.+}?"], name: "上海市发展和改革委员会", url: "fgw.sh.gov.cn", maintainers: ["nczitzk"], handler, example: "/gov/sh/fgw/fgw_zxxxgk", parameters: { category: "分类,默认为 `fgw_zxxxgk`,即最新信息公开,可在对应分类页 URL 中找到" }, description: `::: tip 若订阅 [最新信息公开](https://fgw.sh.gov.cn/fgw_zxxxgk/index.html),网址为 \`https://fgw.sh.gov.cn/fgw_zxxxgk/index.html\`。截取 \`https://fgw.sh.gov.cn/\` 到末尾 \`/index.html\` 的部分 \`fgw_zxxxgk\` 作为参数填入,此时路由为 [\`/gov/sh/fgw/fgw_zxxxgk\`](https://rsshub.app/gov/sh/fgw/fgw_zxxxgk)。 ::: | 最新信息公开 | 要闻动态 | | ------------ | ---------- | | fgw_zxxxgk | fgw_fzggdt | `, categories: ["government"], features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportRadar: true, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [ { source: ["fgw.sh.gov.cn/:category"], target: (params) => { const category = params.category.replace(/\/index\.html/, ""); return `/gov/sh/fgw${category ? `/${category}` : ""}`; } }, { title: "最新信息公开", source: ["fgw.sh.gov.cn/fgw_zxxxgk/index.html"], target: "/sh/fgw/fgw_zxxxgk" }, { title: "要闻动态", source: ["fgw.sh.gov.cn/fgw_fzggdt/index.html"], target: "/sh/fgw/fgw_fzggdt" } ] }; //#endregion export { handler, route };