UNPKG

rsshub

Version:
85 lines (82 loc) 3.49 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 { r as getSubPath } from "./common-utils-vrWQFAEk.mjs"; import { t as got_default } from "./got-KxxWdaxq.mjs"; import { load } from "cheerio"; //#region lib/routes/gov/nsfc/shortcuts.ts var shortcuts_default = { jjyw: "/publish/portal0/tab440/", tzgg: "/publish/portal0/tab442/", bmdt: "/publish/portal0/tab445/", kpkx: "/publish/portal0/tab446/", zzcg: "/publish/portal0/tab448/", "zcfg-jjtl": "/publish/portal0/tab471/", "zcfg-fzgh": "/publish/portal0/tab473/", "zcfg-gzzd": "/publish/portal0/tab475/", "zcfg-flfg": "/publish/portal0/tab609/", "glkxb-gzdt": "/publish/portal0/tab1210/", "glkxb-tzgg": "/publish/portal0/tab1212/", "glkxb-zzcg": "/publish/portal0/tab1213/", "gjhzj-xmzn": "/publish/portal0/tab1356/", "gjhzj-csjg": "/publish/portal0/tab1361/", "gjhzj-pztz": "/publish/portal0/tab1362/", "gjhzj-jcjb": "/publish/portal0/tab1366/", "gjhzj-xxgk": "/publish/portal0/tab1386/" }; //#endregion //#region lib/routes/gov/nsfc/index.ts const route = { path: "/nsfc/*", name: "Unknown", maintainers: [], handler }; async function handler(ctx) { let thePath = getSubPath(ctx).replace(/^\/nsfc/, ""); const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit"), 10) : 30; const shortcutMatches = thePath.match(/(\/news)?\/([\w-]+)/); if (shortcutMatches) { const shortcut = shortcutMatches[2]; if (Object.hasOwn(shortcuts_default, shortcut)) thePath = shortcuts_default[shortcut]; } const rootUrl = "https://www.nsfc.gov.cn"; const currentUrl = new URL((/\/more$/.test(thePath) ? `${thePath}.htm` : thePath) || "publish/portal0/tab442/", rootUrl).href; const { data: response } = await got_default(currentUrl, { https: { rejectUnauthorized: false } }); const $ = load(response); let items = $("span.fl a, ul.dp_lia li a").slice(0, limit).toArray().map((item) => { item = $(item); return { title: item.prop("title") ?? item.text(), link: new URL(item.prop("href"), rootUrl).href, guid: `nsfc-${item.prop("id")}`, pubDate: parseDate(item.next().text().replace(/\[]/g, "", ["YYYY-MM-DD", "YY-MM-DD"])) }; }); items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => { const { data: detailResponse } = await got_default(item.link, { https: { rejectUnauthorized: false } }); const content = load(detailResponse); item.title = content("div.title_xilan").text(); item.description = content("#zoom").html(); item.author = content("meta[name=\"docauthor\"]").prop("content"); item.category = [content("meta[name=\"channel\"]").prop("content"), content("meta[name=\"docsource\"]").prop("content")]; item.pubDate = parseDate(content("div.line_xilan").text().match(/日期 (\d{4}-\d{2}-\d{2})/)[1]); return item; }))); return { item: items, title: `国家自然科学基金委员会 - ${$("#ess_essBREADCRUMB_lblBreadCrumb a.break").toArray().slice(1).map((a) => $(a).text()).join(" - ")}`, link: currentUrl, description: $("meta[name=\"DESCRIPTION\"]").prop("content"), language: "zh-cn", subtitle: $("meta[name=\"KEYWORDS\"]").prop("content"), author: $("meta[name=\"AUTHOR\"]").prop("content") }; } //#endregion export { route };