UNPKG

rsshub

Version:
83 lines (81 loc) 2.5 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 { n as finishArticleItem } from "./wechat-mp-Dq_pp853.mjs"; import { load } from "cheerio"; //#region lib/routes/pku/nsd.ts const baseUrl = "https://nsd.pku.edu.cn/sylm/gd/"; const pageType = (href) => { if (!href.startsWith("http")) return "in-site"; const url = new URL(href); if (url.hostname === "mp.weixin.qq.com") return "wechat-mp"; else if (url.hostname === "news.pku.edu.cn") return "pku-news"; else return "unknown"; }; const route = { path: "/nsd/gd", categories: ["university"], example: "/pku/nsd/gd", parameters: {}, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["nsd.pku.edu.cn/"] }], name: "观点 - 国家发展研究院", maintainers: ["MisLink"], handler, url: "nsd.pku.edu.cn/" }; async function handler() { const $ = load((await got_default({ url: baseUrl, https: { rejectUnauthorized: false } })).data); const list = $("div.maincontent > ul > li").toArray().map((item) => { const href = $(item).find("a").attr("href"); const type = pageType(href); return { title: $(item).find("a").text().trim(), link: type === "in-site" ? baseUrl + href : href, pubDate: parseDate($(item).find("span").first().text(), "YYYY-MM-DD"), type }; }); return { title: "观点 - 北京大学国家发展研究院", link: baseUrl, item: await Promise.all(list.map((item) => { switch (item.type) { case "wechat-mp": return finishArticleItem(item); case "pku-news": return cache_default.tryGet(item.link, async () => { item.description = load((await got_default({ url: item.link, https: { rejectUnauthorized: false } })).data)("div.pageArticle > div.col.lf").html(); return item; }); case "in-site": return cache_default.tryGet(item.link, async () => { item.description = load((await got_default({ url: item.link, https: { rejectUnauthorized: false } })).data)("div.article").html(); return item; }); default: return item; } })) }; } //#endregion export { route };