UNPKG

rsshub

Version:
47 lines (45 loc) 1.84 kB
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs"; import { t as parseDate } from "./parse-date-CjhZE69i.mjs"; import { t as cache_default } from "./cache-CiDoUSLo.mjs"; import { t as timezone } from "./timezone-DE--ze1V.mjs"; import { load } from "cheerio"; //#region lib/routes/gov/cppcc/index.ts const route = { path: "/:slug?", categories: ["government"], example: "/gov/cppcc", parameters: { slug: "见下文" }, name: "栏目", maintainers: ["nczitzk"], description: `将目标栏目的网址拆解为 \`http://www.cppcc.gov.cn/\` 和后面的字段,去掉末尾的 \`/\` 后,把字段中的 \`/\` 替换为 \`-\`,即为该路由的 slug 如:(要闻)\`http://www.cppcc.gov.cn/zxxw/yw/\` 的网址在 \`http://www.cppcc.gov.cn/\` 后的字段是 \`zxxw/yw/\`,则对应的 slug 为 \`zxxw-yw\`,对应的路由即为 \`/gov/cppcc/zxxw-yw\``, handler }; async function handler(ctx) { const { slug = "zxxw-yw" } = ctx.req.param(); const currentUrl = `http://www.cppcc.gov.cn/${slug.replaceAll("-", "/")}/`; const response = await rofetch(currentUrl); const $ = load(response); const list = $("#txtBox li").toArray().map((item) => { const $item = $(item); const a = $item.find("a"); return { title: a.text(), link: new URL(a.attr("href"), currentUrl).href, pubDate: timezone(parseDate($item.find(".time").text()), 8) }; }); const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => { const content = load(await rofetch(item.link)); item.description = content(".cnt_box .con").html(); item.author = content(".info em").text().split(":", 2)[1]; return item; }))); return { title: `${response.match(/<span style="padding:0 8px">><\/span>(.*?)<\/p>/)[1]} - 中国政协网`, link: currentUrl, item: items }; } //#endregion export { route };