/
index.ts
112 lines (100 loc) · 3.66 KB
/
index.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import { Route } from '@/types';
import { getCurrentPath } from '@/utils/helpers';
const __dirname = getCurrentPath(import.meta.url);
import cache from '@/utils/cache';
import got from '@/utils/got';
import timezone from '@/utils/timezone';
import { parseDate } from '@/utils/parse-date';
import { art } from '@/utils/render';
import path from 'node:path';
export const route: Route = {
path: ['/column/:id?', '/:id?'],
categories: ['traditional-media'],
example: '/cankaoxiaoxi/column/diyi',
parameters: { id: '栏目 id,默认为 `diyi`,即第一关注' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
name: '栏目',
maintainers: ['yuxinliu-alex', 'nczitzk'],
handler,
description: `| 栏目 | id |
| -------------- | -------- |
| 第一关注 | diyi |
| 中国 | zhongguo |
| 国际 | gj |
| 观点 | guandian |
| 锐参考 | ruick |
| 体育健康 | tiyujk |
| 科技应用 | kejiyy |
| 文化旅游 | wenhualy |
| 参考漫谈 | cankaomt |
| 研究动态 | yjdt |
| 海外智库 | hwzk |
| 业界信息・观点 | yjxx |
| 海外看中国城市 | hwkzgcs |
| 译名趣谈 | ymymqt |
| 译名发布 | ymymfb |
| 双语汇 | ymsyh |
| 参考视频 | video |
| 军事 | junshi |
| 参考人物 | cankaorw |`,
};
async function handler(ctx) {
const id = ctx.req.param('id') ?? 'diyi';
const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 50;
const rootUrl = 'https://china.cankaoxiaoxi.com';
const listApiUrl = `${rootUrl}/json/channel/${id}/list.json`;
const channelApiUrl = `${rootUrl}/json/channel/${id}.channeljson`;
const currentUrl = `${rootUrl}/#/generalColumns/${id}`;
const listResponse = await got({
method: 'get',
url: listApiUrl,
});
const channelResponse = await got({
method: 'get',
url: channelApiUrl,
});
let items = listResponse.data.list.slice(0, limit).map((item) => ({
title: item.data.title,
author: item.data.userName,
category: item.data.channelName,
pubDate: timezone(parseDate(item.data.publishTime), +8),
link: item.data.moVideoPath ? item.data.sourceUrl : `${rootUrl}/json/content/${item.data.url.match(/\/pages\/(.*?)\.html/)[1]}.detailjson`,
video: item.data.moVideoPath,
cover: item.data.mCoverImg,
}));
items = await Promise.all(
items.map((item) =>
cache.tryGet(item.link, async () => {
if (item.video) {
item.description = art(path.join(__dirname, 'templates/description.art'), {
video: item.video,
cover: item.cover,
});
} else {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const data = detailResponse.data;
item.link = `${rootUrl}/#/detailsPage/${id}/${data.id}/1/${data.publishTime.split(' ')[0]}`;
item.description = data.txt;
}
return item;
})
)
);
return {
title: `参考消息 - ${channelResponse.data.name}`,
link: currentUrl,
description: '参考消息',
language: 'zh-cn',
item: items,
};
}