Skip to content

Commit d98ee1b

Browse files
authored
feat: add shmtu portal notification (DIYgod#11414)
* add shmtu portal notification * fix: only get the latest 5 news * maintain entries in alphabetical order * Update lib/v2/shmtu/router.js, maintain entries in alphabetical order * chore: adjust alphabetical order of rader * chore: get the latest 8 news instead of 5 * chore: remove the limit on the number of feeds
1 parent 97b651e commit d98ee1b

File tree

5 files changed

+76
-0
lines changed

5 files changed

+76
-0
lines changed

docs/university.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2366,6 +2366,14 @@ jsjxy.hbut.edu.cn 证书链不全,自建 RSSHub 可设置环境变量 NODE_TLS
23662366
| ---- | ---- |
23672367
| jwgg | jwxw |
23682368

2369+
### 数字平台
2370+
2371+
<Route author="imbytecat" example="/shmtu/portal/bmtzgg" path="/shmtu/portal/:type" :paramsDesc="['类型名称']"/>
2372+
2373+
| 部门通知公告 |
2374+
| ---- |
2375+
| bmtzgg |
2376+
23692377
## 上海海洋大学
23702378

23712379
### 官网信息

lib/v2/shmtu/maintainer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module.exports = {
22
'/jwc/:type': ['simonsmh'],
3+
'/portal/:type': ['imbytecat'],
34
'/www/:type': ['simonsmh'],
45
};

lib/v2/shmtu/portal.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
const got = require('@/utils/got');
2+
const cheerio = require('cheerio');
3+
const { parseDate } = require('@/utils/parse-date');
4+
const timezone = require('@/utils/timezone');
5+
const bootstrapHost = 'https://weixin.shmtu.edu.cn/dynamic/shmtuHttps';
6+
const host = 'https://portal.shmtu.edu.cn/api';
7+
8+
const loadDetail = async (link) => {
9+
const response = await got.post(bootstrapHost, {
10+
form: {
11+
interfaceUrl: link,
12+
},
13+
https: { rejectUnauthorized: false },
14+
});
15+
16+
return JSON.parse(response.data);
17+
};
18+
19+
const processFeed = (list, caches) =>
20+
Promise.all(
21+
list.map((item) =>
22+
caches.tryGet(item.link, async () => {
23+
const detail = await loadDetail(item.link);
24+
item.description = detail.body.und[0].safe_value;
25+
item.link = detail.path;
26+
return item;
27+
})
28+
)
29+
);
30+
31+
module.exports = async (ctx) => {
32+
const type = ctx.params.type;
33+
const info = type === 'bmtzgg' ? '部门通知公告' : '未知';
34+
35+
const response = await got.post(bootstrapHost, {
36+
form: {
37+
interfaceUrl: `${host}/${type}.json?page=0`,
38+
},
39+
https: { rejectUnauthorized: false },
40+
});
41+
42+
const list = JSON.parse(response.data).map((item) => ({
43+
title: cheerio.load(item.title).text(),
44+
link: `${host}/node/${item.nid}.json`,
45+
pubDate: timezone(parseDate(item.created), 8),
46+
category: item.field_department[0],
47+
author: item.field_department[0],
48+
}));
49+
50+
const result = await processFeed(list, ctx.cache);
51+
52+
ctx.state.data = {
53+
title: `上海海事大学 ${info}`,
54+
link: 'https://portal.shmtu.edu.cn/bumentongzhigonggao',
55+
description: '上海海事大学 数字平台',
56+
item: result,
57+
};
58+
};

lib/v2/shmtu/radar.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ module.exports = {
99
target: '/shmtu/jwc/:type',
1010
},
1111
],
12+
portal: [
13+
{
14+
title: '数字平台',
15+
docs: 'https://docs.rsshub.app/university.html#shang-hai-dian-li-da-xue',
16+
source: ['/:type'],
17+
target: '/shmtu/portal/:type',
18+
},
19+
],
1220
www: [
1321
{
1422
title: '官网信息',

lib/v2/shmtu/router.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module.exports = (router) => {
22
router.get('/jwc/:type', require('./jwc'));
3+
router.get('/portal/:type', require('./portal'));
34
router.get('/www/:type', require('./www'));
45
};

0 commit comments

Comments
 (0)