UNPKG

rsshub

Version:
81 lines (79 loc) 2.59 kB
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 { t as ofetch_default } from "./ofetch-BIyrKU3Y.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 path from "node:path"; import { load } from "cheerio"; //#region lib/routes/ieee/author.ts init_esm_shims(); const route = { name: "IEEE Author Articles", maintainers: ["Derekmini"], categories: ["journal"], path: "/author/:aid/:sortType", parameters: { aid: "Author ID", sortType: "Sort Type of papers" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: true }, example: "/ieee/author/37264968900/newest", handler }; async function handler(ctx) { const { aid, sortType } = ctx.req.param(); const count = ctx.req.query("limit") || 10; const host = "https://ieeexplore.ieee.org"; const author = (await ofetch_default(`${host}/rest/author/${aid}`))[0]; const title = `${author.preferredName} on IEEE Xplore`; const link = `${host}/author/${aid}`; const description = author.bioParagraphs.join(" "); const image = `${host}${author.photoUrl}`; const list = (await ofetch_default(`${host}/rest/search`, { method: "POST", body: { rowsPerPage: count, searchWithin: [`"Author Ids": ${aid}`], sortType } })).records.map((item) => ({ title: item.articleTitle, link: item.htmlLink, doi: item.doi, authors: "authors" in item ? item.authors.map((itemAuth) => itemAuth.preferredName).join("; ") : "Do not have author", abstract: "abstract" in item ? item.abstract : "" })); return { title, link, description, item: await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => { if (item.abstract !== "") { const metadataMatch = load(await ofetch_default(`${host}${item.link}`, { parseResponse: (txt) => txt })).html().match(/metadata=(.*);/); const metadata = metadataMatch ? JSON.parse(metadataMatch[1]) : null; item.pubDate = metadata?.insertDate ? parseDate(metadata.insertDate) : void 0; item.abstract = load(metadata?.abstract || "").text(); } return { ...item, description: renderDescription(item) }; }))), image }; } function renderDescription(item) { return art(path.join(__dirname, "templates/description-e509e615.art"), { item }); } //#endregion export { route };