UNPKG

rsshub

Version:
47 lines (45 loc) 1.94 kB
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs"; import { t as config } from "./config-C37vj7VH.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 { r as getSubPath } from "./common-utils-vrWQFAEk.mjs"; import { t as art } from "./render-BQo6B4tL.mjs"; import path from "node:path"; import { load } from "cheerio"; //#region lib/routes/nber/common.ts init_esm_shims(); async function getData(url) { return (await ofetch_default(url)).results; } async function handler(ctx) { const url = "https://www.nber.org/api/v1/working_page_listing/contentType/working_paper/_/_/search"; const baseUrl = "https://www.nber.org"; const data = await cache_default.tryGet(url, () => getData(url), config.cache.routeExpire, false); return { title: "NBER Working Paper", link: "https://www.nber.org/papers", item: await Promise.all(data.filter((article) => getSubPath(ctx) === "/papers" || article.newthisweek).map((article) => { const link = `${baseUrl}${article.url}`; return cache_default.tryGet(link, async () => { const $ = load(await ofetch_default(link)); const downloadLink = $("meta[name=\"citation_pdf_url\"]").attr("content"); const fullAbstract = $(".page-header__intro-inner").html(); return { title: article.title, author: $("meta[name=\"dcterms.creator\"]").attr("content"), pubDate: parseDate($("meta[name=\"citation_publication_date\"]").attr("content"), "YYYY/MM/DD"), link, doi: $("meta[name=\"citation_doi\"]").attr("content"), description: art(path.join(__dirname, "templates/description-9c2e727f.art"), { fullAbstract, downloadLink }) }; }); })), description: `National Bureau of Economic Research Working Papers articles` }; } //#endregion export { handler as t };