rsshub
Version:
Make RSS Great Again!
90 lines (88 loc) • 2.87 kB
JavaScript
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs";
import { t as ofetch_default } from "./ofetch-BIyrKU3Y.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/psyche/utils.ts
init_esm_shims();
const getImageById = async (id) => {
return (await ofetch_default("https://api.aeonmedia.co/graphql", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
query: "query getImageById($id: ID!) { image(id: $id) { id url alt caption width height } }",
variables: {
id,
site: "Aeon"
},
operationName: "getImageById"
})
})).data.image.url;
};
function format(article) {
const type = article.type.toLowerCase();
let block = "";
let banner = "";
let authorsBio = "";
switch (type) {
case "film":
block = art(path.join(__dirname, "templates/video-ab57a74c.art"), { article });
break;
case "guide": {
banner = article.imageSquare?.url;
authorsBio = article.authors.map((author) => author.bio).join(" ");
const sectionNames = [
"Need To Know",
"What To Do",
"Key Points",
"Learn More",
"Links & Books"
];
const content = Object.keys(article).filter((key) => key.startsWith("section") && key !== "section").map((section) => {
const capture = load(article[section]);
capture("p.pullquote").remove();
return `<h2>${sectionNames.shift()}</h2>` + capture.html();
}).join("");
block = art(path.join(__dirname, "templates/essay-18b14798.art"), {
banner,
authorsBio,
content
});
break;
}
case "idea": {
banner = article.imageLandscape?.url;
authorsBio = article.authors.map((author) => author.bio).join(" ");
const capture = load(article.body);
capture("p.pullquote").remove();
block = art(path.join(__dirname, "templates/essay-18b14798.art"), {
banner,
authorsBio,
content: capture.html()
});
break;
}
default: break;
}
return block;
}
const getData = async (list) => {
return await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => {
const article = (await ofetch_default(item.json)).pageProps.article;
item.pubDate = new Date(article.publishedAt).toUTCString();
const capture = load(format(article));
await Promise.all(capture("dl > dt").toArray().map(async (item$1) => {
const id = capture(item$1).text();
const image = await getImageById(id);
capture(item$1).replaceWith(`<img src="${image}" alt="${id}">`);
}));
let authors = "";
authors = article.type === "film" ? article.creditsShort : article.authors.map((author) => author.name).join(", ");
item.description = capture.html();
item.author = authors;
return item;
})));
};
//#endregion
export { getData as t };