/
report.ts
124 lines (109 loc) · 4.27 KB
/
report.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
113
114
115
116
117
118
119
120
121
122
123
124
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 { load } from 'cheerio';
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: ['/lc_report/:id?', '/report/:id?'],
categories: ['new-media'],
example: '/logclub/lc_report',
parameters: { id: '报告 id,见下表,默认为罗戈研究出品' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
name: '报告',
maintainers: ['nczitzk'],
handler,
description: `| 罗戈研究出品 | 物流报告 | 绿色双碳报告 |
| ------------ | -------------- | --------------------- |
| Report | IndustryReport | GreenDualCarbonReport |`,
};
async function handler(ctx) {
const { id = 'Report' } = ctx.req.param();
const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 11;
const rootUrl = 'https://www.logclub.com';
const currentUrl = new URL('lc_report', rootUrl).href;
const apiUrl = new URL(`front/lc_report/load${id}List`, rootUrl).href;
const { data: response } = await got.post(apiUrl, {
json: {
page: 1,
},
});
let items = response.list.slice(0, limit).map((item) => ({
title: item.title,
link: new URL(`front/lc_report/get_report_info/${item.id}`, rootUrl).href,
description: art(path.join(__dirname, 'templates/description.art'), {
image: {
src: item.img_url?.split(/\?/)[0] ?? undefined,
alt: item.title,
},
}),
author: item.author,
category: [item.channel_name],
guid: `logclub-report-${item.id}`,
pubDate: timezone(parseDate(item.release_time), +8),
}));
items = await Promise.all(
items.map((item) =>
cache.tryGet(item.link, async () => {
const { data: detailResponse } = await got(item.link);
const content = load(detailResponse);
content('img').each((_, el) => {
el = content(el);
el.replaceWith(
art(path.join(__dirname, 'templates/description.art'), {
image: {
src: el.prop('src')?.split(/\?/)[0] ?? undefined,
alt: el.prop('title'),
},
})
);
});
item.title = content('h1').first().text();
item.description += art(path.join(__dirname, 'templates/description.art'), {
description: content('div.article-cont').html(),
});
item.author = content('div.lc-infos a')
.toArray()
.map((a) => content(a).text())
.join('/');
item.category = [
...new Set([
...(item.category ?? []),
...content('div.article-label-r a.label')
.toArray()
.map((c) => content(c).text()),
]),
].filter(Boolean);
return item;
})
)
);
const { data: currentResponse } = await got(currentUrl);
const $ = load(currentResponse);
const title = $('div.this_nav').text().trim();
const icon = new URL($('link[rel="shortcut icon"]').prop('href'), rootUrl).href;
const subtitle = $('meta[name="keywords"]').prop('content');
return {
item: items,
title: `${$('title').text()}${title}`,
link: currentUrl,
description: $('meta[name="description"]').prop('content'),
language: 'zh',
image: new URL($('div.logo_img img').prop('src'), rootUrl).href,
icon,
logo: icon,
subtitle: subtitle.replaceAll(',', ''),
author: subtitle.split(/,/)[0],
};
}