diff --git a/lib/routes/anthropic/namespace.ts b/lib/routes/anthropic/namespace.ts new file mode 100644 index 00000000000000..f11fc642cd2092 --- /dev/null +++ b/lib/routes/anthropic/namespace.ts @@ -0,0 +1,7 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: 'Anthropic', + url: 'anthropic.com', + lang: 'en', +}; diff --git a/lib/routes/anthropic/news.ts b/lib/routes/anthropic/news.ts new file mode 100644 index 00000000000000..3f95758a7bed51 --- /dev/null +++ b/lib/routes/anthropic/news.ts @@ -0,0 +1,60 @@ +import got from '@/utils/got'; +import { load } from 'cheerio'; +import cache from '@/utils/cache'; + +export const route: Route = { + path: '/news', + categories: ['programming'], + example: '/anthropic/news', + parameters: {}, + radar: [ + { + source: ['anthropic.com'], + }, + ], + name: 'News', + maintainers: ['etShaw-zh'], + handler, + url: 'anthropic.com/news', +}; + +async function handler() { + const link = 'https://anthropic.com/news'; + const response = await got(link); + const $ = load(response.body); + + const list = $('.contentFadeUp a') + .toArray() + .map((e) => { + e = $(e); + const title = e.find('h3.PostCard_post-heading__KPsva').text().trim(); // Extract title + const href = e.attr('href'); // Extract link + const pubDate = e.find('.PostList_post-date__giqsu').text().trim(); // Extract publication date + const fullLink = href.startsWith('http') ? href : `https://anthropic.com${href}`; // Complete relative links + return { + title, + link: fullLink, + pubDate, + }; + }); + + const out = await Promise.all( + list.map((item) => + cache.tryGet(item.link, async () => { + const response = await got(item.link); + const $ = load(response.body); + + item.description = $('.text-b2.PostDetail_post-detail__uTcjp').html() || ''; // Full article content + + return item; + }) + ) + ); + + return { + title: 'Anthropic News', + link, + description: 'Latest news from Anthropic', + item: out, + }; +}