UNPKG

rsshub

Version:
127 lines (125 loc) 4.93 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 { t as timezone } from "./timezone-BBvDwS_3.mjs"; import { Fragment, jsx, jsxs } from "hono/jsx/jsx-runtime"; import { load } from "cheerio"; import { renderToString } from "hono/jsx/dom/server"; import { raw } from "hono/html"; //#region lib/routes/gov/sh/fgw/index.tsx const renderDescription = ({ images, description }) => renderToString(/* @__PURE__ */ jsxs(Fragment, { children: [images?.length ? images.map((image) => image?.src ? /* @__PURE__ */ jsx("figure", { children: /* @__PURE__ */ jsx("img", { src: image.src, alt: image.alt }) }, image.src) : null) : null, description ? /* @__PURE__ */ jsx(Fragment, { children: raw(description) }) : null] })); const handler = async (ctx) => { const { category = "fgw_zxxxgk" } = ctx.req.param(); const limit = ctx.req.query("limit") ? Number(ctx.req.query("limit")) : 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) => { const $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 = $$("div.pdf-content img").first().prop("src"); const description = renderDescription({ images: image ? [{ src: image, 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 = [.../* @__PURE__ */ 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; item.banner = image; 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: "/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: "/fgw/fgw_zxxxgk" }, { title: "要闻动态", source: ["fgw.sh.gov.cn/fgw_fzggdt/index.html"], target: "/fgw/fgw_fzggdt" } ] }; //#endregion export { handler, route };