/
thebatch.ts
62 lines (57 loc) 路 1.94 KB
/
thebatch.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
export const route: Route = {
path: '/thebatch',
categories: ['programming'],
example: '/deeplearning/thebatch',
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['www.deeplearning.ai/thebatch', 'www.deeplearning.ai/'],
},
],
name: 'TheBatch 鍛ㄦ姤',
maintainers: ['nczitzk', 'juvenn'],
handler,
url: 'www.deeplearning.ai/thebatch',
};
async function handler() {
const page = await got({
method: 'get',
url: `https://www.deeplearning.ai/the-batch/`,
});
const nextJs = page.data.match(/<script id="__NEXT_DATA__" type="application\/json">(.*)<\/script>/)[1];
const nextBuildId = JSON.parse(nextJs).buildId;
const listing = await got({
method: 'get',
url: `https://www.deeplearning.ai/_next/data/${nextBuildId}/the-batch.json`,
});
const items = listing.data.pageProps.posts.map((item) => ({
title: item.title,
link: `https://www.deeplearning.ai/the-batch/${item.slug}`,
jsonUrl: `https://www.deeplearning.ai/_next/data/${nextBuildId}/the-batch/${item.slug}.json`,
pubDate: new Date(item.published_at).toUTCString(),
}));
return {
title: `The Batch - a new weekly newsletter from deeplearning.ai`,
link: `https://www.deeplearning.ai/the-batch/`,
item: await Promise.all(
items.map((item) =>
cache.tryGet(item.link, async () => {
const resp = await got({ method: 'get', url: item.jsonUrl });
item.description = resp.data.pageProps.cmsData.post.html;
return item;
})
)
),
};
}