rsshub
Version:
Make RSS Great Again!
60 lines (58 loc) • 1.75 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 { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs";
import { t as cache_default } from "./cache-Bo__VnGm.mjs";
import { t as rss_parser_default } from "./rss-parser-Dtop7M8f.mjs";
import { load } from "cheerio";
//#region lib/routes/nytimes/rss.ts
const route = {
path: "/rss/:cat?",
categories: ["traditional-media"],
view: ViewType.Articles,
example: "/nytimes/rss/HomePage",
parameters: { cat: { description: "Category name, corresponding to the last segment of [official feed's](https://www.nytimes.com/rss) url." } },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [{
source: ["nytimes.com/"],
target: ""
}],
name: "News",
maintainers: [
"HenryQW",
"pseudoyu",
"dzx-dzx"
],
handler,
url: "nytimes.com/",
description: `Enhance the official EN RSS feed`
};
async function handler(ctx) {
const url = `https://rss.nytimes.com/services/xml/rss/nyt/${ctx.req.param("cat")}.xml`;
const rss = await rss_parser_default.parseURL(url);
return {
...rss,
item: await Promise.all(rss.items.map((e) => cache_default.tryGet(e.link, async () => {
const $ = load(await ofetch_default(e.link, {
headers: { "User-Agent": "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" },
referrer: "https://www.google.com/"
}));
return {
...e,
description: $("[name='articleBody']").html(),
author: $("meta[name=\"byl\"]").attr("content")
};
})))
};
}
//#endregion
export { route };