/
reviews.ts
50 lines (44 loc) · 1.36 KB
/
reviews.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
import { Route } from '@/types';
import ofetch from '@/utils/ofetch';
import { load } from 'cheerio';
import { baseUrl, parseItem } from './utils';
export const route: Route = {
path: '/reviews/:type?',
categories: ['new-media'],
example: '/dcfever/reviews/cameras',
parameters: { type: '分類,預設為 `cameras`' },
radar: [
{
source: ['dcfever.com/:type/reviews.php'],
target: '/reviews/:type',
},
],
name: '測試報告',
maintainers: ['TonyRL'],
handler,
description: `| 相機及鏡頭 | 手機平板 | 試車報告 |
| ---------- | -------- | -------- |
| cameras | phones | cars |`,
};
async function handler(ctx) {
const { type = 'cameras' } = ctx.req.param();
const link = `${baseUrl}/${type}/reviews.php`;
const response = await ofetch(link);
const $ = load(response);
const list = $('.col-md-left .title a')
.toArray()
.map((item) => {
item = $(item);
return {
title: item.text(),
link: new URL(item.attr('href'), link).href,
};
});
const items = await Promise.all(list.map((item) => parseItem(item)));
return {
title: $('head title').text(),
link,
image: 'https://cdn10.dcfever.com/images/android_192.png',
item: items,
};
}