feat: add 西安交通大学国际处通知 (#5500)

This commit is contained in:
Guitao Liu 2020-08-23 04:07:14 +08:00 committed by GitHub
parent f867063140
commit 20776d4c66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 63 additions and 5 deletions

View File

@ -1530,11 +1530,7 @@ type 列表:
### 教务处
<Route author="hoilc" example="/xjtu/dean/jxxx/xytz/ksap" path="/xjtu/dean/:subpath+" :paramsDesc="['栏目路径, 支持多级, 不包括末尾的`.htm`']" />
### 研究生院通知公告
<Route author="nczitzk" example="/xjtu/gs/tzgg" path="/xjtu/gs/tzgg"/>
<Route author="hoilc" example="/xjtu/dean/jxxx/xytz/ksap" path="/xjtu/dean/:subpath+" :paramsDesc="['栏目路径, 支持多级, 不包括末尾的`.htm`']" >
::: tip 提示
@ -1548,6 +1544,14 @@ type 列表:
</Route>
### 国际处通知
<Route author="guitaoliu" example="/xjtu/international/hzjl" path="/xjtu/international/:subpath+" :paramsDesc="['栏目路径, 支持多级, 不包括末尾的`.htm`']" />
### 研究生院通知公告
<Route author="nczitzk" example="/xjtu/gs/tzgg" path="/xjtu/gs/tzgg" />
## 西南财经大学
### 经济信息工程学院

View File

@ -2505,6 +2505,7 @@ router.get('/wolley/host/:host', require('./routes/wolley/host'));
// 西安交大
router.get('/xjtu/gs/tzgg', require('./routes/universities/xjtu/gs/tzgg'));
router.get('/xjtu/dean/:subpath+', require('./routes/universities/xjtu/dean'));
router.get('/xjtu/international/:subpath+', require('./routes/universities/xjtu/international'));
// booksource
router.get('/booksource', require('./routes/booksource/index'));

View File

@ -0,0 +1,53 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const subpath = ctx.params.subpath;
const base = 'http://international.xjtu.edu.cn';
const url = `${base}/${subpath.split('.')[0]}.htm`;
const resp = await got({
method: 'get',
url: url,
});
const $ = cheerio.load(resp.data);
const name = $('div.pageTitle').text();
const list = $('.news-list-a > .c').get();
const item = await Promise.all(
list.map(async (item) => {
const $ = cheerio.load(item);
const title = $('p.list-tit');
const pubDate = $('p.list-time');
const link = new URL($('a').attr('href'), base).href;
const cache = await ctx.cache.get(link);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const resp = await got.get(link);
const $Des = cheerio.load(resp.data);
const description = $Des('div.ctnCont').html();
const rssItem = {
title: title.text(),
link: link,
pubDate: new Date(pubDate.text()),
description,
};
ctx.cache.set(rssItem, JSON.stringify(rssItem));
return Promise.resolve(rssItem);
})
);
ctx.state.data = {
title: `西安交通大学国际处 - ${name}`,
link: url,
description: `西安交通大学国际处 - ${name}`,
item,
};
};