UNPKG

rsshub

Version:
39 lines (38 loc) 1.29 kB
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs"; import { t as parseDate } from "./parse-date-CjhZE69i.mjs"; import { t as cache_default } from "./cache-CiDoUSLo.mjs"; import { load } from "cheerio"; //#region lib/routes/ustr/press-releases.ts const route = { path: "/press-releases", categories: ["government"], example: "/ustr/press-releases", name: "Press Releases", maintainers: ["nczitzk"], handler }; async function handler(ctx) { const rootUrl = "https://ustr.gov"; const currentUrl = `${rootUrl}/about-us/policy-offices/press-office/press-releases`; const $ = load(await rofetch(currentUrl)); const list = $(".view-content .views-row").toArray().slice(0, ctx.req.query("limit") ? Number(ctx.req.query("limit")) : 15).map((item) => { const $item = $(item); const a = $item.find(".views-field-title a"); return { title: a.text(), link: `${rootUrl}${a.attr("href")}`, pubDate: parseDate($item.find("time").attr("datetime")) }; }); const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => { item.description = load(await rofetch(item.link))(".field--name-body").html() ?? void 0; return item; }))); return { title: $("title").text(), link: currentUrl, item: items }; } //#endregion export { route };