rsshub
Version:
Make RSS Great Again!
93 lines (91 loc) • 3.57 kB
JavaScript
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs";
import "./config-C37vj7VH.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 art } from "./render-BQo6B4tL.mjs";
import { t as got_default } from "./got-KxxWdaxq.mjs";
import { FetchError } from "ofetch";
import path from "node:path";
import dayjs from "dayjs";
import timezone from "dayjs/plugin/timezone.js";
import utc from "dayjs/plugin/utc.js";
import advancedFormat from "dayjs/plugin/advancedFormat.js";
//#region lib/routes/washingtonpost/app.ts
init_esm_shims();
const route = {
path: "/app/:category{.+}?",
categories: ["traditional-media"],
example: "/washingtonpost/app/national",
parameters: { category: "Category from the path of the URL of the corresponding site, see below" },
features: {
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
name: "App",
maintainers: ["quiniapiezoelectricity"],
radar: [{
source: ["www.washingtonpost.com/:category"],
target: "/app/:category"
}],
handler,
description: `::: tip
For example, the category for https://www.washingtonpost.com/national/investigations would be /national/investigations.
:::`
};
function handleDuplicates(array) {
const objects = {};
for (const obj of array) objects[obj.id] = objects[obj.id] ? Object.assign(objects[obj.id], obj) : obj;
return Object.values(objects);
}
async function handler(ctx) {
const category = ctx.req.param("category") ?? "";
const headers = {
Accept: "*/*",
Connection: "keep-alive",
"User-Agent": "Classic/6.70.0"
};
dayjs.extend(utc);
dayjs.extend(timezone);
dayjs.extend(advancedFormat);
art.defaults.imports.dayjs = dayjs;
const url = `https://jsonapp1.washingtonpost.com/fusion_prod/v2/${category}`;
const response = await got_default.get(url, { headers });
const title = response.data.tracking.page_title.includes("Washington Post") ? response.data.tracking.page_title : `The Washington Post - ${response.data.tracking.page_title}`;
const link = "https://washingtonpost.com" + response.data.tracking.page_path;
const feed = handleDuplicates(response.data.regions[0].items.filter((item) => item.items).flatMap((main) => main.items[0].items.filter((item) => item.is_from_feed === true).map((item) => {
const object = {
id: item.id,
title: item.headline.text,
link: item.link.url,
pubDate: item.link.display_date,
updated: item.link.last_modified
};
if (item.blurbs?.items[0]?.text) object.description = item.blurbs?.items[0]?.text;
return object;
})));
return {
title,
link,
item: await Promise.all(feed.map((item) => cache_default.tryGet(item.link, async () => {
let response$1;
try {
response$1 = await got_default(`https://rainbowapi-a.wpdigital.net/rainbow-data-service/rainbow/content-by-url.json?followLinks=false&url=${item.link}`, { headers });
} catch (error) {
if (error instanceof FetchError && error.statusCode === 415) return item;
else throw error;
}
item.title = response$1.data.title ?? item.title;
item.author = response$1.data.items.filter((entry) => entry.type === "byline")?.flatMap((entry) => entry.authors.map((author) => author.name))?.join(", ") ?? "";
item.description = art(path.join(__dirname, "templates/description-8c76ddeb.art"), { content: response$1.data.items });
return item;
})))
};
}
//#endregion
export { route };