rsshub
Version:
Make RSS Great Again!
65 lines (63 loc) • 1.86 kB
JavaScript
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs";
import { n as parseRelativeDate } from "./parse-date-CjhZE69i.mjs";
import { t as cache_default } from "./cache-CiDoUSLo.mjs";
import { load } from "cheerio";
//#region lib/routes/zhishifenzi/news.ts
const route = {
path: "/news/:type?",
categories: ["study"],
example: "/zhishifenzi/news/ai",
parameters: { type: "type,eg. ai" },
name: "News",
maintainers: ["y9c"],
handler,
description: `| \`:type\` | type name |
| --------- | --------- |
| biology | Biology |
| medicine | Medicine |
| ai | AI |
| physics | physics |
| chymistry | Chymistry |
| astronomy | Astronomy |
| others | Others |
> leave it blank(\`/zhishifenzi/news\`)to get all`
};
const titles = {
multiple: "综合",
biology: "生物",
medicine: "医药",
ai: "人工智能",
physics: "物理",
chymistry: "化学",
astronomy: "天文",
other: "其他"
};
async function handler(ctx) {
const { type = "multiple" } = ctx.req.param();
const rootUrl = "https://zhishifenzi.com";
const $ = load(await rofetch(`${rootUrl}/news/ajaxarticles`, {
method: "POST",
body: new URLSearchParams({ category: type })
}));
const list = $("h5 a").toArray().map((item) => {
const $item = $(item);
return {
title: $item.text(),
link: new URL($item.attr("href"), rootUrl).href
};
});
const out = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => {
const content = load(await rofetch(item.link));
item.description = content(".inner_content").html();
item.pubDate = parseRelativeDate(content(".inner_view_from").text());
return item;
})));
return {
title: `知識分子 | 資訊「${titles[type] || "综合"}」`,
description: "知識分子 | 科學 文明 智慧",
link: `${rootUrl}/news`,
item: out
};
}
//#endregion
export { route };