UNPKG

rsshub

Version:
61 lines (59 loc) 2.21 kB
import "./dist-Bog6z_OM.mjs"; import "./config-MQ-7ebJ_.mjs"; import "./logger-C4avouvV.mjs"; import "./ofetch-DKl_Ma9g.mjs"; import { t as parseDate } from "./parse-date-r5WDWHno.mjs"; import "./is-worker-DESPicPc.mjs"; import { t as cache_default } from "./cache-SV6W5EPy.mjs"; import "./helpers-Bo4JQYdN.mjs"; import { t as got_default } from "./got-CO-ndVl2.mjs"; import { t as timezone } from "./timezone-CA9Huotp.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 };