UNPKG

rsshub

Version:
51 lines (49 loc) 1.78 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 * as cheerio from "cheerio"; //#region lib/routes/12371/zxfb.ts const handler = async (ctx) => { const { category = "zxfb" } = ctx.req.param(); const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit"), 10) : 15; const currentUrl = `https://www.12371.cn/${category}/`; const response = await got_default(currentUrl); const $ = cheerio.load(response.data); const topNewsList = JSON.parse($("script[language=\"javascript\"]").text().match(/item=(\[{.*?}]);/)?.[1].replaceAll("'", "\"") || "[]").slice(0, limit).map((item) => ({ title: item.title, pubDate: timezone(parseDate(item.brief, "YYYY-MM-DD HH:mm:ss"), 8), link: item.link_add })); const items = await Promise.all(topNewsList.map((item) => cache_default.tryGet(item.link, async () => { const detailResponse = await got_default(item.link); item.description = cheerio.load(detailResponse.data)(".word").html(); return item; }))); return { title: $("title").text(), link: currentUrl, item: items }; }; const route = { path: "/:category?", example: "/12371/zxfb", parameters: { category: "新闻分类名,预设 `zxfb`" }, radar: [{ source: ["www.12371.cn/:category"] }], name: "最新发布", maintainers: ["zvrr"], handler, url: "www.12371.cn", description: `| 最新发布 | | :------: | | zxfb |` }; //#endregion export { route };