/
news.ts
55 lines (51 loc) 路 1.52 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
import { Route } from '@/types';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
const newsUrl = 'https://www.cpuid.com/news.html';
export const route: Route = {
path: '/news',
categories: ['program-update'],
example: '/cpuid/news',
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['cpuid.com/news.html', 'cpuid.com/'],
},
],
name: 'News',
maintainers: [],
handler,
url: 'cpuid.com/news.html',
};
async function handler() {
const response = await got(newsUrl);
const $ = load(response.data);
const items = $('.block_100 .js-block-news')
.toArray()
.map((item) => {
item = $(item);
return {
title: item.find('.information a').text(),
description: item.find('.description').html(),
link: item.find('.information a').attr('href'),
pubDate: parseDate(item.find('time[itemprop=dateCreated]').attr('datetime')),
};
});
return {
title: $('head title').text(),
description: $('head description').attr('content'),
link: newsUrl,
image: $('link[rel=apple-touch-icon-precomposed]').attr('href'),
item: items,
language: $('html').attr('lang'),
};
}