UNPKG

rsshub

Version:
71 lines (69 loc) 2.63 kB
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs"; import { t as config } from "./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 path from "node:path"; import { load } from "cheerio"; //#region lib/routes/informs/index.ts init_esm_shims(); const rootUrl = "https://pubsonline.informs.org"; const route = { path: "/:category?", categories: ["journal"], example: "/informs/mnsc", parameters: { category: "Category, can be found in the url of the page, `orsc` by default" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, name: "Category", maintainers: ["Fatpandac"], handler }; async function handler(ctx) { const category = ctx.req.param("category") ?? "orsc"; const cateUrl = `${rootUrl}/toc/${category}/0/0`; const getCookie = () => cache_default.tryGet(cateUrl, async () => { const setCookiesUrl = `${cateUrl}?cookieSet=1`; return (await got_default.extend({ followRedirect: false }).get(setCookiesUrl, { headers: { Referer: cateUrl } })).headers["set-cookie"].slice(1).map((item) => item.split(";")[0]).join("; "); }); const $ = load((await got_default.get(cateUrl, { headers: { referer: cateUrl, "User-Agent": config.ua, cookie: await getCookie() } })).data); const list = $("div.issue-item").slice(0, 10).toArray().map((item) => ({ title: $(item).find("h5.issue-item__title").text(), link: `${rootUrl}${$(item).find("h5.issue-item__title > a").attr("href")}`, pubDate: parseDate($(item).find("div.rlist--inline.separator.toc-item__detail > p").remove("span").text()) })); const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => { const detail = load((await got_default.get(item.link, { headers: { referer: cateUrl, "User-Agent": config.ua, cookie: await getCookie() } })).data); item.description = art(path.join(__dirname, "templates/content-720e37b1.art"), { author: detail("div.accordion-tabbed.loa-accordion").text(), content: detail("div.hlFld-Abstract").find("h2").replaceWith($("<h2>Abstract </h2>")).end().html() }); return item; }))); return { title: `INFORMS - ${category}`, link: cateUrl, item: items }; } //#endregion export { route };