/
news.ts
66 lines (64 loc) 路 1.96 KB
/
news.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
63
64
65
66
import { Route } from '@/types';
import cache from '@/utils/cache';
import parser from '@/utils/rss-parser';
import got from '@/utils/got';
import { load } from 'cheerio';
const host = 'https://techcrunch.com';
export const route: Route = {
path: '/news',
categories: ['new-media'],
example: '/techcrunch/news',
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['techcrunch.com/'],
},
],
name: 'News',
maintainers: ['EthanWng97'],
handler,
url: 'techcrunch.com/',
};
async function handler() {
const rssUrl = `${host}/feed/`;
const feed = await parser.parseURL(rssUrl);
const items = await Promise.all(
feed.items.map((item) =>
cache.tryGet(item.link, async () => {
const url = item.link;
const response = await got({
url,
method: 'get',
});
const html = response.data;
const $ = load(html);
const description = $('#root');
description.find('.article__title').remove();
description.find('.article__byline__meta').remove();
description.find('.mobile-header-nav').remove();
description.find('.desktop-nav').remove();
return {
title: item.title,
pubDate: item.pubDate,
link: item.link,
category: item.categories,
description: description.html(),
};
})
)
);
return {
title: 'TechCrunch',
link: host,
description: 'Reporting on the business of technology, startups, venture capital funding, and Silicon Valley.',
item: items,
};
}