UNPKG

rsshub

Version:
67 lines (66 loc) 2.56 kB
import { t as config } from "./config-CCmw1BNE.mjs"; import { t as parseDate } from "./parse-date-Cr0wQjV_.mjs"; import { t as cache_default } from "./cache-BkqOokyU.mjs"; import { n as outPlaywright } from "./playwright-o20DiLNh.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", categories: ["journal"], example: "/acs/journal/jacsat", parameters: { id: "Journal id, can be found in URL" }, features: { supportScihub: true }, radar: [{ source: ["pubs.acs.org/journal/:id", "pubs.acs.org/"] }], name: "Journal", maintainers: ["nczitzk"], handler, description: `::: tip See [Browse Content](https://pubs.acs.org) :::` }; 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 context = await outPlaywright(); const items = await cache_default.tryGet(currentUrl, async () => { const page = await context.newPage(); await page.route("**/*", (route) => { const request = route.request(); request.resourceType() === "document" || request.resourceType() === "script" ? route.continue() : route.abort(); }); await page.goto(currentUrl, { waitUntil: "domcontentloaded" }); await page.waitForSelector(".toc"); const html = await page.evaluate(() => document.documentElement.getHTML()); await page.close(); const $ = load(html); title = $("meta[property=\"og:title\"]").attr("content"); return $(".issue-item").toArray().map((item) => { const $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 context.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 };