rsshub
Version:
Make RSS Great Again!
71 lines (70 loc) • 2.58 kB
JavaScript
import { t as parseDate } from "./parse-date-Cr0wQjV_.mjs";
import { t as cache_default } from "./cache-BkqOokyU.mjs";
import { t as got_default } from "./got-BTowW50G.mjs";
import { Fragment, jsxs } from "hono/jsx/jsx-runtime";
import { load } from "cheerio";
import { renderToString } from "hono/jsx/dom/server";
import { raw } from "hono/html";
//#region lib/routes/cntheory/paper.tsx
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: renderToString(/* @__PURE__ */ jsxs(Fragment, { children: [content("#reslist").html() ? raw(content("#reslist").html().replaceAll("display:none;", "")) : null, content("founder-content").html() ? raw(content("founder-content").html()) : null] }))
};
})));
return {
title: `学习时报${id ? ` - ${id}` : ""}`,
link: rootUrl,
item: items,
allowEmpty: true
};
}
//#endregion
export { route };