UNPKG

rsshub

Version:
75 lines (73 loc) 2.89 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/nifdc/index.ts const route = { path: "/nifdc/:path{.+}?", name: "Unknown", maintainers: [], handler }; async function handler(ctx) { const { path = "bshff/ylqxbzhgl/qxggtzh" } = ctx.req.param(); const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit"), 10) : 30; const rootUrl = "https://www.nifdc.org.cn"; const currentUrl = new URL(`nifdc/${path}/`, rootUrl).href; const { data: response } = await got_default(currentUrl); const $ = load(response); let items = $("div.list ul li").slice(0, limit).toArray().map((item) => { item = $(item); const a = item.find("a"); const link = a.prop("href"); return { title: a.prop("title") || a.text(), link: link.startsWith("http") ? link : new URL(link, currentUrl).href, pubDate: parseDate(item.find("span").text().replaceAll(/\(|\)/g, "")) }; }); items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => { try { const { data: detailResponse } = await got_default(item.link); const content = load(detailResponse); item.title = content(".title").text(); item.description = content("div.text").append(content("div.fujian")).html(); item.author = content("meta[name=\"ContentSource\"]").prop("content"); item.category = [...new Set([ content("meta[name=\"ColumnName\"]").prop("content"), content("meta[name=\"ColumnType\"]").prop("content"), ...content("meta[name=\"ColumnKeywords\"]").prop("content").split(/,|;/) ?? [] ])].filter(Boolean); item.pubDate = timezone(parseDate(content("meta[name=\"PubDate\"]").prop("content")), 8); item.enclosure_url = content("a.fujianClass").first().prop("href"); if (item.enclosure_url) { item.enclosure_url = new URL(item.enclosure_url, rootUrl).href; item.enclosure_type = `application/${item.enclosure_url.split(/\./).pop()}`; } } catch {} return item; }))); const image = new URL($("div.logo img").prop("src"), currentUrl).href; const icon = new URL($("link[rel=\"shortcut icon\"]").prop("href"), currentUrl).href; return { item: items, title: $("title").text().replace(/----/, " - "), link: currentUrl, description: $("meta[name=\"ColumnDescription\"]").prop("content"), language: "zh", image, icon, logo: icon, subtitle: $("meta[ name=\"ColumnName\"]").prop("content"), author: $("meta[name=\"SiteName\"]").prop("content") }; } //#endregion export { route };