rsshub
Version:
Make RSS Great Again!
65 lines (63 loc) • 2.27 kB
JavaScript
import "./dist-Bog6z_OM.mjs";
import "./config-MQ-7ebJ_.mjs";
import "./logger-C4avouvV.mjs";
import { t as ofetch_default } from "./ofetch-DKl_Ma9g.mjs";
import "./is-worker-DESPicPc.mjs";
import { t as cache_default } from "./cache-SV6W5EPy.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 $ = load(await ofetch_default(link));
const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit"), 10) : 20;
return {
title: "Anthropic News",
link,
description: "Latest news from Anthropic",
item: await pMap($(".contentFadeUp a").toArray().slice(0, limit).map((el) => {
const $el = $(el);
const title = $el.find("h3").text().trim();
const href = $el.attr("href") ?? "";
const pubDate = $el.find("p.detail-m.agate").text().trim() || $el.find("div[class^=\"PostList_post-date__\"]").text().trim();
return {
title,
link: href.startsWith("http") ? href : `https://www.anthropic.com${href}`,
pubDate
};
}), (item) => cache_default.tryGet(item.link, async () => {
const $ = load(await ofetch_default(item.link));
const content = $("#main-content");
$(`
[class^="PostDetail_post-heading"],
[class^="ArticleDetail_sidebar-container"],
[class^="QuoteCarousel_carousel-controls"],
[class^="PostDetail_b-social-share"],
[class^="LandingPageSection_root"],
[class^="CodeBlock_controls"]
`).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() ?? void 0;
return item;
}), { concurrency: 5 })
};
}
//#endregion
export { route };