Skip to content

Commit

Permalink
feat(route): Add RSS feed for latest news from Anthropic (a leading L…
Browse files Browse the repository at this point in the history
…LM developer). (#17960)

* Add Anthropic news

* Update lib/routes/anthropic/news.ts

---------
  • Loading branch information
etShaw-zh authored Dec 22, 2024
1 parent 8a58ca1 commit d525693
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/routes/anthropic/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: 'Anthropic',
url: 'anthropic.com',
lang: 'en',
};
60 changes: 60 additions & 0 deletions lib/routes/anthropic/news.ts
Original file line number Diff line number Diff line change
@@ -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,
};
}

0 comments on commit d525693

Please sign in to comment.