Skip to content

Commit 049adef

Browse files
authored
feat(route/anthropic): add engineering (#19070)
1 parent f1d56ed commit 049adef

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import ofetch from '@/utils/ofetch';
2+
import { load } from 'cheerio';
3+
import cache from '@/utils/cache';
4+
import { Route } from '@/types';
5+
import pMap from 'p-map';
6+
import { parseDate } from '@/utils/parse-date';
7+
8+
export const route: Route = {
9+
path: '/engineering',
10+
categories: ['programming'],
11+
example: '/anthropic/engineering',
12+
radar: [
13+
{
14+
source: ['www.anthropic.com/engineering', 'www.anthropic.com'],
15+
},
16+
],
17+
name: 'Engineering',
18+
maintainers: ['TonyRL'],
19+
handler,
20+
url: 'www.anthropic.com/engineering',
21+
};
22+
23+
async function handler() {
24+
const baseUrl = 'https://www.anthropic.com';
25+
const link = `${baseUrl}/engineering`;
26+
const response = await ofetch(link);
27+
const $ = load(response);
28+
29+
const list = $('a[class^="ArticleList_cardLink__"]')
30+
.toArray()
31+
.map((element) => {
32+
const $e = $(element);
33+
return {
34+
title: $e.find('h2, h3').text().trim(),
35+
link: `${baseUrl}${$e.attr('href')}`,
36+
};
37+
});
38+
39+
const items = await pMap(
40+
list,
41+
(item) =>
42+
cache.tryGet(item.link, async () => {
43+
const response = await ofetch(item.link);
44+
const $ = load(response);
45+
46+
const content = $('div[class^="Body_body__"]');
47+
content.find('img').each((_, e) => {
48+
const $e = $(e);
49+
$e.removeAttr('style srcset');
50+
const src = $e.attr('src');
51+
const params = new URLSearchParams(src);
52+
const newSrc = params.get('/_next/image?url');
53+
if (newSrc) {
54+
$e.attr('src', newSrc);
55+
}
56+
});
57+
58+
item.pubDate = parseDate($('p[class*="HeroEngineering_date__"]').text().trim().replaceAll('Published ', ''));
59+
item.description = content.html();
60+
61+
return item;
62+
}),
63+
{ concurrency: 5 }
64+
);
65+
66+
return {
67+
title: 'Anthropic Engineering',
68+
link,
69+
image: `${baseUrl}/images/icons/apple-touch-icon.png`,
70+
item: items,
71+
};
72+
}

0 commit comments

Comments
 (0)