UNPKG

rsshub

Version:
62 lines (60 loc) 2.44 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 "./ofetch-BIyrKU3Y.mjs"; import { t as parseDate } from "./parse-date-BrP7mxXf.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 path from "node:path"; import { load } from "cheerio"; //#region lib/routes/nationalgeographic/latest-stories.ts init_esm_shims(); const findNatgeo = ($) => JSON.parse($("script").text().match(/\['__natgeo__']=({.*?});/)[1]); const route = { path: "/latest-stories", categories: ["travel"], example: "/nationalgeographic/latest-stories", parameters: {}, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["www.nationalgeographic.com/pages/topic/latest-stories"] }], name: "Latest Stories", maintainers: ["miles170"], handler, url: "www.nationalgeographic.com/pages/topic/latest-stories" }; async function handler() { const currentUrl = "https://www.nationalgeographic.com/pages/topic/latest-stories"; const $ = load((await got_default(currentUrl)).data); const items = await Promise.all(findNatgeo($).page.content.hub.frms.flatMap((e) => e.mods).flatMap((m) => m.tiles?.filter((t) => t.ctas[0]?.text === "natgeo.ctaText.read")).filter(Boolean).map((i) => ({ title: i.title, link: i.ctas[0].url, category: i.tags.map((t) => t.name) })).map((item) => cache_default.tryGet(item.link, async () => { const bodyTile = findNatgeo(load((await got_default(item.link)).data)).page.content.prismarticle.frms.find((f) => f.cmsType === "ArticleBodyFrame").mods.find((m) => m.edgs[0].cmsType === "ArticleBodyTile").edgs[0]; item.author = bodyTile.cntrbGrp.flatMap((c) => c.contributors).map((c) => c.displayName).join(", "); item.description = art(path.join(__dirname, "templates/stories-ce453fa9.art"), { ldMda: bodyTile.ldMda, description: bodyTile.dscrptn, body: bodyTile.bdy }); item.pubDate = parseDate(bodyTile.pbDt); return item; }))); return { title: $("meta[property=\"og:title\"]").attr("content"), link: currentUrl, item: items.filter((item) => item !== null) }; } //#endregion export { route };