UNPKG

rsshub

Version:
94 lines (90 loc) 3.59 kB
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 { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs"; import { t as parseDate } from "./parse-date-BrP7mxXf.mjs"; import { t as cache_default } from "./cache-Bo__VnGm.mjs"; import { t as art } from "./render-BQo6B4tL.mjs"; import { t as PRESETS } from "./header-generator-BYLlSJoA.mjs"; import path from "node:path"; import { load } from "cheerio"; //#region lib/routes/theatlantic/utils.ts init_esm_shims(); const getArticleDetails = async (items) => { return await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => { const url = item.link; const $ = load(await ofetch_default(url, { headerGeneratorOptions: PRESETS.MODERN_ANDROID })); let data = JSON.parse($("script#__NEXT_DATA__").text()); const list = data.props.pageProps.urqlState; const keyWithContent = Object.keys(list).filter((key) => list[key].data.includes("content")); data = JSON.parse(list[keyWithContent].data).article; item.title = data.shareTitle; item.category = data.categories.map((category) => category.slug); for (const channel of data.channels) item.category.push(channel.slug); item.content = data.content.filter((item$1) => item$1.innerHtml !== void 0 && item$1.innerHtml !== ""); item.caption = data.dek; if (data.leadArt) { item.imgUrl = data.leadArt.image?.url; item.imgAlt = data.leadArt.image?.altText; item.imgCaption = data.leadArt.image?.attributionText; } item.description = art(path.join(__dirname, "templates/article-description-c1053caf.art"), { item }); return { title: item.title, pubDate: parseDate(item.pubDate), link: item.link, description: item.description }; }))); }; //#endregion //#region lib/routes/theatlantic/news.ts const route = { path: "/:category", categories: ["traditional-media"], example: "/theatlantic/latest", parameters: { category: "category, see below" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["www.theatlantic.com/:category"] }], name: "News", maintainers: ["EthanWng97", "pseudoyu"], handler, description: `| Popular | Latest | Politics | Technology | Business | | ------------ | ------ | -------- | ---------- | -------- | | most-popular | latest | politics | technology | business | More categories (except photo) can be found within the navigation bar at [https://www.theatlantic.com](https://www.theatlantic.com)` }; async function handler(ctx) { const host = "https://www.theatlantic.com"; const category = ctx.req.param("category"); const url = `${host}/${category}/`; const $ = load(await ofetch_default(url)); const contents = JSON.parse($("script#__NEXT_DATA__").text()).props.pageProps.urqlState; const keyWithContent = Object.keys(contents).filter((key) => contents[key].data.includes(category)); const data = JSON.parse(contents[keyWithContent].data); let list = Object.values(data)[0].river.edges; list = list.filter((item) => !item.node.url.startsWith("https://www.theatlantic.com/photo")); list = list.map((item) => { return { link: item.node.url, pubDate: item.node.datePublished }; }); const items = await getArticleDetails(list); return { title: `The Atlantic - ${category.toUpperCase()}`, link: url, description: `The Atlantic - ${category.toUpperCase()}`, item: items }; } //#endregion export { route };