rsshub
Version:
Make RSS Great Again!
67 lines (65 loc) • 2.46 kB
JavaScript
import "./esm-shims-CzJ_djXG.mjs";
import "./config-C37vj7VH.mjs";
import { t as ViewType } from "./types-D84BRIt4.mjs";
import "./dist-BInvbO1W.mjs";
import "./logger-Czu8UMNd.mjs";
import "./ofetch-BIyrKU3Y.mjs";
import { t as cache_default } from "./cache-Bo__VnGm.mjs";
import "./helpers-DxBp0Pty.mjs";
import { t as got_default } from "./got-KxxWdaxq.mjs";
import { t as rss_parser_default } from "./rss-parser-Dtop7M8f.mjs";
import { load } from "cheerio";
//#region lib/routes/economist/full.ts
const getArticleDetail = (link) => cache_default.tryGet(link, async () => {
const $ = load((await got_default(link)).data);
$("div.article-audio-player__center-tooltip").remove();
const nextData = JSON.parse($("head script[type=\"application/ld+json\"]").first().text());
return {
article: ($("figure[class^=css-]").first().parent().parent().html() || "") + $("p[data-component=\"paragraph\"]").parent().parent().html(),
categories: nextData.keywords?.map((k) => k)
};
});
const route = {
path: "/:endpoint",
categories: ["traditional-media"],
view: ViewType.Articles,
example: "/economist/latest",
parameters: { endpoint: "Category name, can be found on the [official page](https://www.economist.com/rss). For example, https://www.economist.com/china/rss.xml to china" },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [{ source: ["economist.com/:endpoint"] }],
name: "Category",
maintainers: ["ImSingee"],
handler
};
async function handler(ctx) {
const endpoint = ctx.req.param("endpoint");
const feed = await rss_parser_default.parseURL(`https://www.economist.com/${endpoint}/rss.xml`);
const items = await Promise.all(feed.items.slice(0, ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit"), 10) : 30).map(async (item) => {
const path = item.link.slice(item.link.lastIndexOf("/") + 1);
const isNotCollection = !/^\d{4}-\d{2}-\d{2}$/.test(path);
const itemDetails = isNotCollection ? await getArticleDetail(item.link) : null;
return {
title: item.title,
description: isNotCollection ? itemDetails.article : item.content,
link: item.link,
guid: item.guid,
pubDate: item.pubDate,
category: isNotCollection ? itemDetails.categories : null
};
}));
return {
title: feed.title,
link: feed.link,
description: feed.description,
item: items
};
}
//#endregion
export { route };