rsshub
Version:
Make RSS Great Again!
65 lines (63 loc) • 2.55 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 parseDate } from "./parse-date-BrP7mxXf.mjs";
import "./cache-Bo__VnGm.mjs";
import { t as timezone } from "./timezone-D8cuwzTY.mjs";
import { t as fetchArticle } from "./utils-BOmc80q7.mjs";
import { load } from "cheerio";
import pMap from "p-map";
//#region lib/routes/apnews/sitemap.ts
const HOME_PAGE = "https://apnews.com";
const route = {
path: "/sitemap/:route",
categories: ["traditional-media"],
example: "/apnews/sitemap/ap-sitemap-latest",
view: ViewType.Articles,
parameters: { route: { description: "Route for sitemap, excluding the `.xml` extension" } },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [{ source: ["apnews.com/"] }],
name: "Sitemap",
maintainers: [
"zoenglinghou",
"mjysci",
"TonyRL",
"dzx-dzx"
],
handler
};
async function handler(ctx) {
const route$1 = ctx.req.param("route");
const $ = load(await ofetch_default(`${HOME_PAGE}/${route$1}.xml`));
const list = $("urlset url").toArray().map((e) => {
const LANGUAGE_MAP = new Map([["eng", "en"], ["spa", "es"]]);
const title = $(e).find(String.raw`news\:title`).text();
const pubDate = parseDate($(e).find(String.raw`news\:publication_date`).text());
const lastmod = timezone(parseDate($(e).find(`lastmod`).text()), -4);
const language = LANGUAGE_MAP.get($(e).find(String.raw`news\:language`).text());
let res = { link: $(e).find("loc").text() };
if (title) res = Object.assign(res, { title });
if (pubDate.toString() !== "Invalid Date") res = Object.assign(res, { pubDate });
if (language) res = Object.assign(res, { language });
if (lastmod.toString() !== "Invalid Date") res = Object.assign(res, { lastmod });
return res;
}).filter((e) => Boolean(e.link) && !new URL(e.link).pathname.split("/").includes("hub")).toSorted((a, b) => a.pubDate && b.pubDate ? b.pubDate - a.pubDate : b.lastmod - a.lastmod).slice(0, ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit"), 10) : 20);
const items = ctx.req.query("fulltext") === "true" ? await pMap(list, (item) => fetchArticle(item), { concurrency: 20 }) : list;
return {
title: `AP News sitemap:${route$1}`,
item: items,
link: "https://apnews.com"
};
}
//#endregion
export { route };