UNPKG

rsshub

Version:
66 lines (64 loc) 2.34 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 "./logger-Czu8UMNd.mjs"; import { t as parseDate } from "./parse-date-BrP7mxXf.mjs"; import { t as cache_default } from "./cache-Bo__VnGm.mjs"; import { t as art } from "./render-BQo6B4tL.mjs"; import "./proxy-Db7uGcYb.mjs"; import { n as puppeteer_default } from "./puppeteer-DGmvuGvT.mjs"; import path from "node:path"; import { load } from "cheerio"; //#region lib/routes/acs/journal.ts init_esm_shims(); const route = { path: "/journal/:id", radar: [{ source: ["pubs.acs.org/journal/:id", "pubs.acs.org/"] }], name: "Unknown", maintainers: ["nczitzk"], handler }; async function handler(ctx) { const id = ctx.req.param("id") ?? ""; const rootUrl = "https://pubs.acs.org"; const currentUrl = `${rootUrl}/toc/${id}/0/0`; let title = ""; const browser = await puppeteer_default(); const items = await cache_default.tryGet(currentUrl, async () => { const page = await browser.newPage(); await page.setRequestInterception(true); page.on("request", (request) => { request.resourceType() === "document" || request.resourceType() === "script" ? request.continue() : request.abort(); }); await page.goto(currentUrl, { waitUntil: "domcontentloaded" }); await page.waitForSelector(".toc"); const html = await page.evaluate(() => document.documentElement.innerHTML); await page.close(); const $ = load(html); title = $("meta[property=\"og:title\"]").attr("content"); return $(".issue-item").toArray().map((item) => { item = $(item); const a = item.find(".issue-item_title a"); const doi = item.find("input[name=\"doi\"]").attr("value"); return { doi, guid: doi, title: a.text(), link: `${rootUrl}${a.attr("href")}`, pubDate: parseDate(item.find(".pub-date-value").text(), "MMMM D, YYYY"), author: item.find(".issue-item_loa li").toArray().map((a$1) => $(a$1).text()).join(", "), description: art(path.join(__dirname, "templates/description-78b7ee2b.art"), { image: item.find(".issue-item_img").html(), description: item.find(".hlFld-Abstract").html() }) }; }); }, config.cache.routeExpire, false); await browser.close(); return { title, link: currentUrl, item: items }; } //#endregion export { route };