rsshub
Version:
Make RSS Great Again!
84 lines (81 loc) • 2.98 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/aeaweb/index.ts
init_esm_shims();
const route = {
path: "/:id",
categories: ["journal"],
example: "/aeaweb/aer",
parameters: { id: "Journal id, can be found in URL" },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: true
},
radar: [{ source: ["aeaweb.org/journals/:id", "aeaweb.org/"] }],
name: "Journal",
maintainers: ["nczitzk"],
handler,
description: `The URL of the journal [American Economic Review](https://www.aeaweb.org/journals/aer) is \`https://www.aeaweb.org/journals/aer\`, where \`aer\` is the id of the journal, so the route for this journal is \`/aeaweb/aer\`.
::: tip
More jounals can be found in [AEA Journals](https://www.aeaweb.org/journals).
:::`
};
async function handler(ctx) {
let id = ctx.req.param("id");
const rootUrl = "https://www.aeaweb.org";
const currentUrl = `${rootUrl}/journals/${id}`;
let response = await got_default({
method: "get",
url: currentUrl
});
let $ = load(response.data);
$(".read-more").remove();
id = $("input[name=\"journal\"]").attr("value");
const title = $(".page-title").text();
const description = $(".intro-copy").text();
response = await got_default({
method: "get",
url: `${rootUrl}/journals/search-results?journal=${id}&ArticleSearch[current]=1`
});
$ = load(response.data);
let items = $("h4.title a").toArray().map((item) => {
item = $(item);
return { link: `${rootUrl}${item.attr("href").split("&")[0]}` };
});
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.guid = item.doi;
item.title = content("meta[name=\"citation_title\"]").attr("content");
item.author = content(".author").toArray().map((a) => content(a).text().trim()).join(", ");
item.pubDate = parseDate(content("meta[name=\"citation_publication_date\"]").attr("content"), "YYYY/MM");
item.description = art(path.join(__dirname, "templates/description-384bc71e.art"), { description: content("meta[name=\"twitter:description\"]").attr("content").replace(/\(\w+ \d+\)( - )?/, "") });
return item;
})));
return {
title,
description,
link: currentUrl,
item: items,
language: $("html").attr("lang")
};
}
//#endregion
export { route };