UNPKG

rsshub

Version:
64 lines (62 loc) 2.43 kB
import { t as config } from "./config-MQ-7ebJ_.mjs"; import "./logger-C4avouvV.mjs"; import { t as parseDate } from "./parse-date-r5WDWHno.mjs"; import "./is-worker-DESPicPc.mjs"; import { t as cache_default } from "./cache-SV6W5EPy.mjs"; import "./proxy-CjvoY5ys.mjs"; import { n as puppeteer_default } from "./puppeteer-9J9JS5H4.mjs"; import { Fragment, jsxs } from "hono/jsx/jsx-runtime"; import { load } from "cheerio"; import { renderToString } from "hono/jsx/dom/server"; import { raw } from "hono/html"; //#region lib/routes/acs/journal.tsx 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) => $(a).text()).join(", "), description: renderDescription(item.find(".issue-item_img").html(), item.find(".hlFld-Abstract").html()) }; }); }, config.cache.routeExpire, false); await browser.close(); return { title, link: currentUrl, item: items }; } const renderDescription = (image, description) => renderToString(/* @__PURE__ */ jsxs(Fragment, { children: [image ? raw(image) : null, description ? raw(description) : null] })); //#endregion export { route };