feat: add shmtu portal notification (#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
This commit is contained in:
imbytecat 2022-12-08 21:51:09 +08:00 committed by GitHub
parent 97b651e924
commit d98ee1b5f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 76 additions and 0 deletions

View File

@ -2366,6 +2366,14 @@ jsjxy.hbut.edu.cn 证书链不全,自建 RSSHub 可设置环境变量 NODE_TLS
| ---- | ---- |
| jwgg | jwxw |
### 数字平台
<Route author="imbytecat" example="/shmtu/portal/bmtzgg" path="/shmtu/portal/:type" :paramsDesc="['类型名称']"/>
| 部门通知公告 |
| ---- |
| bmtzgg |
## 上海海洋大学
### 官网信息

View File

@ -1,4 +1,5 @@
module.exports = {
'/jwc/:type': ['simonsmh'],
'/portal/:type': ['imbytecat'],
'/www/:type': ['simonsmh'],
};

58
lib/v2/shmtu/portal.js Normal file
View File

@ -0,0 +1,58 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
const bootstrapHost = 'https://weixin.shmtu.edu.cn/dynamic/shmtuHttps';
const host = 'https://portal.shmtu.edu.cn/api';
const loadDetail = async (link) => {
const response = await got.post(bootstrapHost, {
form: {
interfaceUrl: link,
},
https: { rejectUnauthorized: false },
});
return JSON.parse(response.data);
};
const processFeed = (list, caches) =>
Promise.all(
list.map((item) =>
caches.tryGet(item.link, async () => {
const detail = await loadDetail(item.link);
item.description = detail.body.und[0].safe_value;
item.link = detail.path;
return item;
})
)
);
module.exports = async (ctx) => {
const type = ctx.params.type;
const info = type === 'bmtzgg' ? '部门通知公告' : '未知';
const response = await got.post(bootstrapHost, {
form: {
interfaceUrl: `${host}/${type}.json?page=0`,
},
https: { rejectUnauthorized: false },
});
const list = JSON.parse(response.data).map((item) => ({
title: cheerio.load(item.title).text(),
link: `${host}/node/${item.nid}.json`,
pubDate: timezone(parseDate(item.created), 8),
category: item.field_department[0],
author: item.field_department[0],
}));
const result = await processFeed(list, ctx.cache);
ctx.state.data = {
title: `上海海事大学 ${info}`,
link: 'https://portal.shmtu.edu.cn/bumentongzhigonggao',
description: '上海海事大学 数字平台',
item: result,
};
};

View File

@ -9,6 +9,14 @@ module.exports = {
target: '/shmtu/jwc/:type',
},
],
portal: [
{
title: '数字平台',
docs: 'https://docs.rsshub.app/university.html#shang-hai-dian-li-da-xue',
source: ['/:type'],
target: '/shmtu/portal/:type',
},
],
www: [
{
title: '官网信息',

View File

@ -1,4 +1,5 @@
module.exports = (router) => {
router.get('/jwc/:type', require('./jwc'));
router.get('/portal/:type', require('./portal'));
router.get('/www/:type', require('./www'));
};