UNPKG

rsshub

Version:
56 lines (55 loc) 1.94 kB
import { t as rofetch } from "./ofetch-U0CdpE2g.mjs"; import { t as cache_default } from "./cache-C1Y-9qDV.mjs"; import { load } from "cheerio"; import pMap from "p-map"; //#region lib/routes/anthropic/news.ts const route = { path: "/news", categories: ["programming"], example: "/anthropic/news", parameters: {}, radar: [{ source: ["www.anthropic.com/news", "www.anthropic.com"] }], name: "News", maintainers: ["etShaw-zh", "goestav"], handler, url: "www.anthropic.com/news" }; async function handler(ctx) { const link = "https://www.anthropic.com/news"; const response = await rofetch(link); const $ = load(response); const limit = ctx.req.query("limit") ? Number(ctx.req.query("limit")) : 10; const list = $("[class^=\"PublicationList-module-scss-module__\"][class$=\"__list\"] a").toArray().slice(0, limit).map((el) => { const $el = $(el); const title = $el.find("[class*=\"__title\"]").text().trim(); const href = $el.attr("href") ?? ""; const pubDate = $el.find("time").text().trim(); return { title, link: href.startsWith("http") ? href : `https://www.anthropic.com${href}`, pubDate }; }); return { title: "Anthropic News", link, description: "Latest news from Anthropic", item: await pMap(list, (item) => cache_default.tryGet(item.link, async () => { const response = await rofetch(item.link); const $ = load(response); const content = $("#main-content"); $("[class$=\"__header\"], [class$=\"__socialShare\"], [class*=\"__carousel-controls\"], [class^=\"LandingPageSection-module-scss-module__\"]").remove(); content.find("img").each((_, e) => { const $e = $(e); $e.removeAttr("style srcset"); const src = $e.attr("src"); const newSrc = new URLSearchParams(src).get("/_next/image?url"); if (newSrc) $e.attr("src", newSrc); }); item.description = content.html(); return item; }), { concurrency: 5 }) }; } //#endregion export { route };