/
news.ts
94 lines (88 loc) · 2.92 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
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
import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
import { finishArticleItem } from '@/utils/wechat-mp';
export const route: Route = {
path: '/uae/:id',
categories: ['university'],
example: '/hrbeu/uae/xwdt',
parameters: { id: '栏目编号,在 `URL` 中获取,如果有多级编号,将 `/` 替换为 `-`。' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: true,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['uae.hrbeu.edu.cn/:id.htm'],
},
],
name: '水声工程学院',
maintainers: [],
handler,
description: `| 新闻动态 | 通知公告 | 科学研究 / 科研动态 |
| :------: | :------: | :-----------------: |
| xwdt | tzgg | kxyj-kydt |`,
};
async function handler(ctx) {
const id = ctx.req.param('id').replaceAll('-', '/');
const host = 'http://uae.hrbeu.edu.cn';
const url = `${host}/${id}.htm`;
const response = await got(url, {
headers: {
Referer: host,
},
});
const $ = load(response.data);
const title = $('h2').text();
const items = $('li.wow.fadeInUp')
.map((_, item) => {
const title = $(item).find('a').attr('title');
let link = $(item).find('a').attr('href');
if (!link.startsWith('http')) {
link = `${host}/${link}`;
}
const pubDate = parseDate(
$(item)
.find('div.date')
.text()
.replaceAll(/(.*)\/(.*)/g, '$2-$1')
);
return {
title,
pubDate,
link,
};
})
.get();
const item = await Promise.all(
items.map((item) =>
cache.tryGet(item.link, async () => {
if (new URL(item.link).hostname === 'uae.hrbeu.edu.cn') {
const resp = await got(item.link);
const $1 = load(resp.data);
item.description = $1('div.art-body').html();
} else if (new URL(item.link).hostname === 'news.hrbeu.edu.cn') {
const resp = await got(item.link);
const $1 = load(resp.data);
item.description = $1('div#print').html();
} else if (new URL(item.link).hostname === 'mp.weixin.qq.com') {
await finishArticleItem(item);
} else {
item.description = '本文需跳转,请点击标题后阅读';
}
return item;
})
)
);
return {
title: `水声工程学院 - ${title}`,
link: url,
item,
};
}