/
topic.ts
74 lines (64 loc) · 1.96 KB
/
topic.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
import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
export const route: Route = {
path: '/topic/:id',
categories: ['new-media'],
example: '/panewslab/topic/1629365774078402',
parameters: { id: '专题 id,可在地址栏 URL 中找到' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['panewslab.com/'],
},
],
name: '专题',
maintainers: ['nczitzk'],
handler,
url: 'panewslab.com/',
};
async function handler(ctx) {
const id = ctx.req.param('id');
const rootUrl = 'https://panewslab.com';
const apiUrl = `${rootUrl}/webapi/subject/articles?Rn=${ctx.req.query('limit') ?? 25}&LId=1&sid=${id}&tw=0`;
const currentUrl = `${rootUrl}/zh/topiclist/${id}.html`;
const response = await got({
method: 'get',
url: apiUrl,
});
let items = response.data.data.map((item) => ({
title: item.title,
author: item.author.name,
pubDate: parseDate(item.publishTime * 1000),
link: `${rootUrl}/zh/articledetails/${item.id}.html`,
description: `<blockquote>${item.desc}</blockquote>`,
category: item.tags,
}));
items = await Promise.all(
items.map((item) =>
cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = load(detailResponse.data);
item.description += content('#txtinfo').html();
return item;
})
)
);
return {
title: `PANews - ${id}`,
link: currentUrl,
item: items,
};
}