rsshub
Version:
Make RSS Great Again!
50 lines (49 loc) • 1.62 kB
JavaScript
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/cn/tujie.ts
const route = {
path: "/xinwen/tujie/:caty",
categories: ["government"],
example: "/gov/cn/xinwen/tujie/zhengce",
parameters: { caty: "图解分类,见下表" },
name: "图解",
maintainers: ["nczitzk"],
description: `| 图解政策 |
| -------- |
| zhengce |`,
handler
};
const config = { zhengce: {
link: "https://www.gov.cn/xinwen/tujie/zhengce/",
title: "图解政策"
} };
async function handler(ctx) {
const { caty } = ctx.req.param();
const cfg = config[caty];
if (!cfg) throw new Error("Bad category. See <a href=\"https://docs.rsshub.app/routes/government#zhong-guo-zheng-fu-tu-jie\">docs</a>");
const currentUrl = cfg.link;
const $ = load(await rofetch(currentUrl));
const list = $("div.tplgd").slice(0, 15).toArray().map((item) => {
const a = $(item).find("a").eq(1);
return {
title: a.text().trim(),
link: a.attr("href")
};
});
const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => {
const content = load(await rofetch(item.link));
item.description = content("div.pages_content").html();
item.pubDate = timezone(parseDate(content("div.pages-date").text().split("来源:", 1)[0]), 8);
return item;
})));
return {
title: `${cfg.title} - 中国政府网`,
link: currentUrl,
item: items
};
}
//#endregion
export { route };