-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): Add RSS feed for latest news from Anthropic (a leading L…
…LM developer). (#17960) * Add Anthropic news * Update lib/routes/anthropic/news.ts ---------
- Loading branch information
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
} |