增加山东大学研究生院学术活动通知 (#850)
This commit is contained in:
parent
147e6d780c
commit
51f9a2aad2
|
|
@ -1194,6 +1194,10 @@ category 列表:
|
|||
|
||||
<route name="自动化学院新闻" author="jinxiapu" example="/hust/auto/news" path="/universities/hust/auto/news" />
|
||||
|
||||
### 山东大学
|
||||
|
||||
<route name="研究生院学术活动" author="Ji4n1ng" example="/sdu/grad/academic" path="/universities/sdu/grad/academic" />
|
||||
|
||||
## 传统媒体
|
||||
|
||||
### 央视新闻
|
||||
|
|
|
|||
|
|
@ -555,6 +555,9 @@ router.get('/kmust/job/jobfairs', require('./routes/universities/kmust/job/jobfa
|
|||
router.get('/hust/auto/notice/:type?', require('./routes/universities/hust/auto/notice'));
|
||||
router.get('/hust/auto/news/', require('./routes/universities/hust/auto/news'));
|
||||
|
||||
// 山东大学
|
||||
router.get('/sdu/grad/academic', require('./routes/universities/sdu/grad/academic'));
|
||||
|
||||
// ifanr
|
||||
router.get('/ifanr/appso', require('./routes/ifanr/appso'));
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,49 @@
|
|||
const axios = require('../../../../utils/axios');
|
||||
const cheerio = require('cheerio');
|
||||
const url = require('url');
|
||||
|
||||
const host = 'http://www.grad.sdu.edu.cn/';
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const link = url.resolve(host, 'default_xshd_news.site?isDto=&beanName=xshd_newsPageBean&typeCode=0108&pageSize=20&pageIndex=1');
|
||||
const response = await axios.get(link);
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const list = $('#div_more_news a')
|
||||
.map((i, e) => $(e).attr('href'))
|
||||
.get();
|
||||
|
||||
const out = await Promise.all(
|
||||
list.filter((itemUrl) => itemUrl.startsWith('http')).map(async (itemUrl) => {
|
||||
const cache = await ctx.cache.get(itemUrl);
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
|
||||
const response = await axios.get(itemUrl);
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const titleGroup = $('#newsTitle')
|
||||
.children()
|
||||
.text()
|
||||
.split('\n');
|
||||
|
||||
const single = {
|
||||
title: titleGroup[0],
|
||||
link: itemUrl,
|
||||
author: '山东大学研究生院',
|
||||
description: $('.newscontent_1').html(),
|
||||
pubDate: new Date(titleGroup[2].slice(8)),
|
||||
};
|
||||
ctx.cache.set(itemUrl, JSON.stringify(single), 24 * 60 * 60);
|
||||
return Promise.resolve(single);
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: '山东大学研究生院学术活动',
|
||||
link,
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue