rsshub
Version:
Make RSS Great Again!
56 lines (54 loc) • 2.31 kB
JavaScript
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 { t as art } from "./render-BQo6B4tL.mjs";
import path from "node:path";
import { load } from "cheerio";
//#region lib/routes/aeon/utils.ts
init_esm_shims();
const getBuildId = () => cache_default.tryGet("aeon:buildId", async () => {
const $ = load(await ofetch_default("https://aeon.co"));
return JSON.parse($("script#__NEXT_DATA__").text()).buildId;
}, config.cache.routeExpire, false);
const getData = async (list) => {
return await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => {
const data = (await ofetch_default(`https://aeon.co/_next/data/${await getBuildId()}/${item.type}s/${item.slug}.json?id=${item.slug}`)).pageProps.article;
const type = data.type.toLowerCase();
item.pubDate = parseDate(data.publishedAt);
if (type === "video") item.description = art(path.join(__dirname, "templates/video-0418ceff.art"), { article: data });
else {
if (data.audio?.id) {
const response = await ofetch_default("https://api.aeonmedia.co/graphql", {
method: "POST",
body: {
query: `query getAudio($audioId: ID!) {
audio(id: $audioId) {
id
streamUrl
}
}`,
variables: { audioId: data.audio.id },
operationName: "getAudio"
}
});
delete item.image;
item.enclosure_url = response.data.audio.streamUrl;
item.enclosure_type = "audio/mpeg";
}
const capture = load(data.body, null, false);
const banner = data.image;
capture("p.pullquote").remove();
const authorsBio = data.authors.map((author) => "<p>" + author.name + author.authorBio.replaceAll(/^<p>/g, " ")).join("");
item.description = art(path.join(__dirname, "templates/essay-deb2bd55.art"), {
banner,
authorsBio,
content: capture.html()
});
}
return item;
})));
};
//#endregion
export { getData as n, getBuildId as t };