UNPKG

rsshub

Version:
60 lines (58 loc) 2.65 kB
import { t as parseDate } from "./parse-date-Cr0wQjV_.mjs"; import { t as cache_default } from "./cache-BkqOokyU.mjs"; import { t as got_default } from "./got-BTowW50G.mjs"; import { Fragment, jsx, 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/pubmed/trending.tsx const route = { path: "/trending/:filters?", categories: ["journal"], example: "/pubmed/trending", parameters: { filters: "Filters, can be found in URL" }, name: "Trending articles", maintainers: ["y9c", "nczitzk"], handler, description: `::: tip For the parameter **filter**, the \`filter\` parameter in the URL should be split into a string by \`,\`, here is an example. In \`https://pubmed.ncbi.nlm.nih.gov/trending/?filter=simsearch1.fha&filter=pubt.clinicaltrial&filter=pubt.randomizedcontrolledtrial\`, the filter parameters are \`simsearch1.fha\`, \`pubt.clinicaltrial\`, and \`pubt.randomizedcontrolledtrial\`. Therefore, the filter corresponding to the route should be filled with \`simsearch1.fha,pubt.clinicaltrial,pubt.randomizedcontrolledtrial\`, and the route is [\`/pubmed/trending/simsearch1.fha,pubt.clinicaltrial,pubt.randomizedcontrolledtrial\`](https://rsshub.app/pubmed/trending/simsearch1.fha,pubt.clinicaltrial,pubt.randomizedcontrolledtrial) :::` }; async function handler(ctx) { const filters = ctx.req.param("filters"); const rootUrl = "https://pubmed.ncbi.nlm.nih.gov"; const currentUrl = `${rootUrl}/trending${filters ? `?filter=${filters.replaceAll(",", "&filter=")}` : ""}`; const $ = load((await got_default({ method: "get", url: currentUrl })).data); let items = $("a[data-article-id]").toArray().map((item) => { const $item = $(item); return { title: $item.text(), link: `${rootUrl}/${$item.attr("data-article-id")}` }; }); items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => { const content = load((await got_default({ method: "get", url: item.link })).data); item.doi = content("meta[name=\"citation_doi\"]").attr("content"); item.pubDate = parseDate(content("meta[name=\"citation_date\"]").attr("content")); item.description = renderToString(/* @__PURE__ */ jsxs(Fragment, { children: [ content(".authors-list").html() ? raw(content(".authors-list").html()) : null, /* @__PURE__ */ jsx("br", {}), content("#enc-abstract").html() ? raw(content("#enc-abstract").html()) : null ] })); return item; }))); return { title: "Trending page - PubMed", link: currentUrl, item: items }; } //#endregion export { route };