rsshub
Version:
Make RSS Great Again!
58 lines (56 loc) • 1.84 kB
JavaScript
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs";
import "./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/pubmed/trending.ts
init_esm_shims();
const route = {
path: "/trending/:filters?",
name: "Unknown",
maintainers: ["nczitzk"],
handler
};
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) => {
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 = art(path.join(__dirname, "templates/description-f09d77cf.art"), {
authors: content(".authors-list").html(),
abs: content("#enc-abstract").html()
});
return item;
})));
return {
title: "Trending page - PubMed",
link: currentUrl,
item: items
};
}
//#endregion
export { route };