UNPKG

rsshub

Version:
81 lines (79 loc) 2.72 kB
import { n as init_esm_shims, t as __dirname } from "./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 art } from "./render-BQo6B4tL.mjs"; import { t as got_default } from "./got-KxxWdaxq.mjs"; import path from "node:path"; import { load } from "cheerio"; //#region lib/routes/cntheory/paper.ts init_esm_shims(); const route = { path: "/paper/:id?", categories: ["traditional-media"], example: "/cntheory/paper", parameters: { id: "板块,默认为全部" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, name: "学习时报", maintainers: ["nczitzk"], handler, description: `如订阅 **第 A1 版:国内大局**,路由为 [\`/cntheory/paper/国内大局\`](https://rsshub.app/cntheory/paper/国内大局)。` }; async function handler(ctx) { const id = ctx.req.param("id"); const rootUrl = "https://paper.cntheory.com"; let response = await got_default({ method: "get", url: rootUrl }); response = await got_default({ method: "get", url: `${rootUrl}/${response.data.match(/URL=(.*)"/)[1]}` }); const $ = load(response.data); const matches = response.data.match(/images\/(\d{4}-\d{2}\/\d{2})\/\w+\/\w+_brief/); const link = `${rootUrl}/html/${matches[1]}`; let items = []; await Promise.all($("#pageLink").toArray().filter((p) => id ? $(p).text().split(":").pop() === id : true).map((p) => `${link}/${$(p).attr("href").replace(/\.\//, "")}`).map(async (p) => { const page = load((await got_default({ method: "get", url: p })).data); items.push(...page("table").last().find("a").toArray().map((a) => `${link}/${$(a).attr("href")}`)); })); items = await Promise.all(items.map((item) => cache_default.tryGet(item, async () => { const content = load((await got_default({ method: "get", url: item })).data); return { link: item, title: content("h1").text(), pubDate: parseDate(matches[1], "YYYY-MM/DD"), enclosure_url: `${rootUrl}${content(".ban_t a").first().attr("href").match(/(\/images.*)/)[1]}`, description: art(path.join(__dirname, "templates/description-61f5629e.art"), { resource: content("#reslist").html().replaceAll("display:none;", ""), description: content("founder-content").html() }) }; }))); return { title: `学习时报${id ? ` - ${id}` : ""}`, link: rootUrl, item: items, allowEmpty: true }; } //#endregion export { route };