UNPKG

rsshub

Version:
67 lines (65 loc) 1.93 kB
import { t as rofetch } from "./ofetch-U0CdpE2g.mjs"; import { n as parseRelativeDate } from "./parse-date-3kcy2Eau.mjs"; import { t as cache_default } from "./cache-C1Y-9qDV.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 response = await rofetch(`${rootUrl}/news/ajaxarticles`, { method: "POST", body: new URLSearchParams({ category: type }) }); const $ = load(response); 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 detailResponse = await rofetch(item.link); const content = load(detailResponse); 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 };