UNPKG

rsshub

Version:
61 lines (59 loc) 2.21 kB
import "./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 got_default } from "./got-KxxWdaxq.mjs"; import { t as timezone } from "./timezone-D8cuwzTY.mjs"; import { load } from "cheerio"; //#region lib/routes/gov/suzhou/fg.ts const route = { path: "/suzhou/fg/:category{.+}?", name: "Unknown", maintainers: [], handler }; async function handler(ctx) { const { category = "szfgw/ggl/nav_list" } = ctx.req.param(); const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit"), 10) : 30; const rootUrl = "https://fg.suzhou.gov.cn"; const currentUrl = new URL(`${category}.shtml`, rootUrl).href; const { data: response } = await got_default(currentUrl); const $ = load(response); let items = $("h4 a[title]").slice(0, limit).toArray().map((item) => { item = $(item); return { title: item.prop("title") || item.text(), link: new URL(item.prop("href"), rootUrl).href, author: item.find(".author").text(), pubDate: parseDate(item.parent().find("span.time").text().trim()) }; }); items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => { const { data: detailResponse } = await got_default(item.link); const content = load(detailResponse); item.title = content("ucaptitle").text().trim(); item.description = content("ucapcontent").html(); item.author = content("span.ly b").text().trim(); item.pubDate = timezone(parseDate(content("meta[name=\"PubDate\"]").prop("content")), 8); return item; }))); const author = $("meta[name=\"SiteName\"]").prop("content"); const subtitle = $("meta[name=\"ColumnName\"]").prop("content"); const image = new URL($("div.logo img").prop("src"), rootUrl).href; return { item: items, title: `${author} - ${subtitle}`, link: currentUrl, description: $("meta[name=\"ColumnDescription\"]").prop("content"), language: $("html").prop("lang"), image, subtitle, author }; } //#endregion export { route };