UNPKG

rsshub

Version:
69 lines (67 loc) 2.43 kB
import "./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 got_default } from "./got-KxxWdaxq.mjs"; import { t as timezone } from "./timezone-D8cuwzTY.mjs"; import { t as utils_default } from "./utils-8S_qiHQV.mjs"; import { load } from "cheerio"; import pMap from "p-map"; //#region lib/routes/x-mol/paper.ts const route = { path: "/paper/:type/:magazine", categories: ["journal"], example: "/x-mol/paper/0/9", parameters: { type: "type", magazine: "magazine" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: true, supportBT: false, supportPodcast: false, supportScihub: false }, name: "Journal", maintainers: ["cssxsh"], handler }; async function handler(ctx) { const { type, magazine } = ctx.req.param(); const path = `paper/${type}/${magazine}`; const link = new URL(path, utils_default.host).href; const response = await got_default(link, { headers: { Cookie: "journalIndexViewType=grid" } }); const data = response.data; const $ = load(data); const item = await pMap($(".magazine-model-content-new li").toArray().slice(0, ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit"), 10) : 20).map((item$1) => { item$1 = $(item$1); return { title: item$1.find(".magazine-text-title a").text().trim(), link: new URL(item$1.find(".magazine-model-btn a").first().attr("href"), utils_default.host).href, pubDate: timezone(parseDate(item$1.find(".magazine-text-atten").text().match(/\d{4}-\d{2}-\d{2}/)[0], 8)) }; }), (element) => cache_default.tryGet(element.link, async () => { const description = load((await got_default(element.link)).data)(".maga-content"); element.doi = description.find(".itsmblue").eq(1).text().trim(); description.find(".itgaryfirst").remove(); description.find("span").eq(0).remove(); element.author = description.find("span").eq(0).text().trim(); description.find("span").eq(0).remove(); element.description = description.html(); return element; }), { concurrency: 2 }); return { title: $("title").text(), link: response.url, description: $("meta[name=\"description\"]").attr("content"), item }; } //#endregion export { route };