feat(route): Add RSS feed for latest news from Anthropic (a leading LLM developer). (#17960)

* Add Anthropic news

* Update lib/routes/anthropic/news.ts

---------
This commit is contained in:
Jianjun Xiao 2024-12-23 00:23:43 +08:00 committed by GitHub
parent 8a58ca1b77
commit d525693969
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 67 additions and 0 deletions

View File

@ -0,0 +1,7 @@
import type { Namespace } from '@/types';
export const namespace: Namespace = {
name: 'Anthropic',
url: 'anthropic.com',
lang: 'en',
};

View File

@ -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,
};
}