UNPKG

rsshub

Version:
105 lines (103 loc) 2.97 kB
import "./esm-shims-CzJ_djXG.mjs"; import "./config-C37vj7VH.mjs"; import "./dist-BInvbO1W.mjs"; import { t as logger_default } from "./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 { load } from "cheerio"; //#region lib/routes/gov/moe/moe.ts const moeUrl = "https://www.moe.gov.cn/"; const typesIdMap = [ { type: "policy_anal", id: "tt_con2", name: "政策解读" }, { type: "newest_file", id: "nine_con1", name: "最新文件" }, { type: "notice", id: "nine_con2", name: "公告公示" }, { type: "edu_ministry_news", id: "nine_con3", name: "教育部简报" }, { type: "edu_focus_news", id: "eight_con2 .pchide>.TRS_Editor", name: "教育要闻" } ]; const route = { path: "/moe/:type", categories: ["government"], example: "/gov/moe/policy_anal", parameters: { type: "分类名" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, name: "新闻", maintainers: ["Crawler995"], handler, description: `| 政策解读 | 最新文件 | 公告公示 | 教育部简报 | 教育要闻 | | :----------: | :----------: | :------: | :-----------------: | :--------------: | | policy\_anal | newest\_file | notice | edu\_ministry\_news | edu\_focus\_news |` }; async function handler(ctx) { const type = ctx.req.param("type"); let id = ""; let name = ""; for (const item of typesIdMap) if (item.type === type) { id = item.id; name = item.name; } if (id === "") { logger_default.error("The given type not found."); return; } const $ = load((await got_default(moeUrl)).data); const newsLis = $("div#" + id + ">ul>li"); return { title: name, link: moeUrl, item: await Promise.all(newsLis.toArray().map(async (item) => { item = $(item); const firstA = item.find("a"); const itemUrl = new URL(firstA.attr("href"), moeUrl).href; const infos = itemUrl.includes("/live/") ? { description: firstA.html() } : await cache_default.tryGet(itemUrl, async () => { const res = {}; const data = load((await got_default({ method: "get", url: itemUrl, headers: { Referer: moeUrl } })).data); if (itemUrl.includes("www.gov.cn")) res.description = data("#UCAP-CONTENT").html(); else if (itemUrl.includes("srcsite")) res.description = data("div#content_body_xxgk").html(); else if (itemUrl.includes("jyb_")) res.description = data("div.moe-detail-box").html() || data("div#moe-detail-box").html(); return res; }); return { title: firstA.text(), description: infos.description, link: itemUrl, pubDate: parseDate(item.find("span").text(), "MM-DD") }; })) }; } //#endregion export { route };