rsshub
Version:
Make RSS Great Again!
67 lines (66 loc) • 2.26 kB
JavaScript
import { t as rofetch } from "./ofetch-U0CdpE2g.mjs";
import { t as parseDate } from "./parse-date-3kcy2Eau.mjs";
import { t as cache_default } from "./cache-C1Y-9qDV.mjs";
import { t as timezone } from "./timezone-UiMFOuvL.mjs";
import { load } from "cheerio";
//#region lib/routes/gov/mva/index.ts
const route = {
path: "/:type",
categories: ["government"],
example: "/gov/mva/bnxx",
parameters: { type: "分类名" },
name: "中华人民共和国退役军人事务部",
maintainers: ["sunshinenny"],
handler,
description: `| 部内信息 | 政策解读 |
| :------: | :------: |
| bnxx | zcjd |`
};
function loadDetail(link) {
return cache_default.tryGet(link, async () => {
const response = await rofetch(link);
const $ = load(response);
const title = $("#main > div.outerlayer > div > div > h2 > p").text();
const introduce = $("#div_zhengwen > div").html();
const info = $("#main > div.outerlayer > div > div > div.article-info").contents().first().text();
const dateTime = info.slice(info.indexOf("时间:") + 3, info.indexOf("来源:")).trim().replace("年", "-").replace("月", "-").replace("日", "") + ":00";
return {
title,
description: introduce,
link,
pubDate: timezone(parseDate(dateTime), 8),
author: info.slice(info.indexOf("来源:") + 3).trim()
};
});
}
const pages = {
bnxx: "https://www.mva.gov.cn/sy/xx/bnxx/",
zcjd: "https://www.mva.gov.cn/jiedu/zcjd/"
};
async function handler(ctx) {
const { type } = ctx.req.param();
const checkType = {
bnxx: "部内信息",
zcjd: "政策解读"
};
const page = pages[type];
const response = await rofetch(page);
const $ = load(response);
const list = $("#main > div.overview.container.clearfix > div.overview-right.fr > div > div.public_list_team > ul > li > a").toArray();
const items = await Promise.all(list.map(async (item) => {
const itemUrl = new URL($(item).attr("href"), page).href;
return {
link: itemUrl,
guid: itemUrl,
...await loadDetail(itemUrl)
};
}));
return {
title: `中华人民共和国退役军人事务部 - ${checkType[type]}`,
link: page,
description: `中华人民共和国退役军人事务部 - ${checkType[type]} 更新提示`,
item: items
};
}
//#endregion
export { route };