UNPKG

rsshub

Version:
70 lines (68 loc) 2.09 kB
import "./dist-Bog6z_OM.mjs"; import "./config-MQ-7ebJ_.mjs"; import "./logger-C4avouvV.mjs"; import "./ofetch-DKl_Ma9g.mjs"; import { t as parseDate } from "./parse-date-r5WDWHno.mjs"; import "./is-worker-DESPicPc.mjs"; import { t as cache_default } from "./cache-SV6W5EPy.mjs"; import "./helpers-Bo4JQYdN.mjs"; import { t as got_default } from "./got-CO-ndVl2.mjs"; import { load } from "cheerio"; //#region lib/routes/whitehouse/news.ts const route = { path: "/news/:category?", categories: ["government"], example: "/whitehouse/news", parameters: { category: "Category, see below, all by default" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["whitehouse.gov/:category", "whitehouse.gov/"], target: "/news/:category" }], name: "News", maintainers: ["nczitzk", "hkamran80"], handler, description: `| All | Articles | Briefings and Statements | Presidential Actions | Remarks | | --- | -------- | ------------------------ | -------------------- | ------- | | | articles | briefings-statements | presidential-actions | remarks |` }; async function handler(ctx) { const currentUrl = `https://www.whitehouse.gov/${ctx.req.param("category") ?? "news"}/`; const $ = load((await got_default({ method: "get", url: currentUrl })).data); const list = $(".post").toArray().map((item) => { item = $(item); const a = item.find("a").first(); return { title: a.text(), link: a.attr("href"), pubDate: parseDate(item.find("time").attr("datetime")), category: [item.find("a[rel^=tag]").first().text()] }; }); const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => { const $ = load((await got_default({ method: "get", url: item.link })).data); $(".wp-block-whitehouse-topper").remove(); item.description = $(".entry-content").html(); return item; }))); return { title: $("title").text(), link: currentUrl, item: items }; } //#endregion export { route };