UNPKG

rsshub

Version:
106 lines (104 loc) 3.83 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 { t as timezone } from "./timezone-D8cuwzTY.mjs"; import path from "node:path"; import { load } from "cheerio"; //#region lib/routes/eshukan/academic.ts init_esm_shims(); const handler = async (ctx) => { const { id = "1" } = ctx.req.param(); const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit"), 10) : 10; const rootUrl = "https://www.eshukan.com"; const currentUrl = new URL(`academic/index.aspx?cid=${id}`, rootUrl).href; const { data: response } = await got_default(currentUrl); const $ = load(response); let items = $("ul.article li").slice(0, limit).toArray().map((item) => { item = $(item); const a = item.find("a"); const title$1 = a.contents().last().text(); const pubDate = item.find("p span").text().match(/(\d{4}\/\d{2}\/\d{2}\s\d{2}:\d{2}:\d{2})/)?.[1]; item.find("p span").remove(); const description = art(path.join(__dirname, "templates/description-f29cc099.art"), { intro: item.find("p").text() }); return { title: title$1, description, pubDate: pubDate ? timezone(parseDate(pubDate), 8) : void 0, link: new URL(a.prop("href"), currentUrl).href, content: { html: description, text: item.find("p").text() } }; }); items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => { const { data: detailResponse } = await got_default(item.link); const $$ = load(detailResponse); const title$1 = $$("h1").text(); const description = art(path.join(__dirname, "templates/description-f29cc099.art"), { intro: $$("div.summary").html(), description: $$("div.detail").html() }); const pubDate = $$("div.author").text().match(/(\d{4}\/\d{2}\/\d{2}\s\d{2}:\d{2}:\d{2})/)?.[1]; item.title = title$1; item.description = description; item.pubDate = pubDate ? timezone(parseDate(pubDate), 8) : item.pubDate; item.author = $$("div.author a").text(); item.content = { html: description, text: $$("div.detail").text() }; return item; }))); const title = $("title").text(); const image = new URL($("div.logo img").prop("src"), rootUrl).href; return { title, description: $("meta[name=\"description\"]").prop("content"), link: currentUrl, item: items, allowEmpty: true, image, author: title.split(/_/).pop() }; }; const route = { path: "/academic/:id?", name: "学术资讯", url: "www.eshukan.com", maintainers: ["nczitzk"], handler, example: "/eshukan/academic/1", parameters: { category: "栏目 id,默认为 `1`,即期刊动态,可在对应栏目页 URL 中找到" }, description: `::: tip 若订阅 [期刊动态](https://www.eshukan.com/academic/index.aspx?cid=1),网址为 \`https://www.eshukan.com/academic/index.aspx?cid=1\`。截取 \`https://www.eshukan.com/academic/index.aspx?cid=\` 到末尾的部分 \`1\` 作为参数填入,此时路由为 [\`/eshukan/academic/1\`](https://rsshub.app/eshukan/academic/1)。 ::: `, categories: ["study"], features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportRadar: true, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["www.eshukan.com/academic/index.aspx"], target: (_, url) => { url = new URL(url); const id = url.searchParams.get("id"); return `/academic${id ? `/${id}` : ""}`; } }] }; //#endregion export { handler, route };