diff --git a/docs/README.md b/docs/README.md index ca33b6dfee..7e81cfeefb 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1474,6 +1474,12 @@ GitHub 官方也提供了一些 RSS: | -------- | -------- | -------- | -------- | -------- | -------- | -------- | | tzgg | xwdt | kydt | jxdt | xsgz | zsxx | jyxx | + + +| 最近动态 | 研院新闻 | 上级文件 | 管理文件 | 信息服务 | +| -------- | -------- | -------- | -------- | -------- | +| latest | yyxw | sjwj | glwj | xxfw | + ### 哈尔滨工业大学 diff --git a/lib/router.js b/lib/router.js index a74ea8bb32..a34a7abe19 100644 --- a/lib/router.js +++ b/lib/router.js @@ -570,6 +570,7 @@ router.get('/seu/cse/:type?', require('./routes/universities/seu/cse')); // 南京航空航天大学 router.get('/nuaa/jwc/:type?', require('./routes/universities/nuaa/jwc/jwc')); router.get('/nuaa/cs/:type?', require('./routes/universities/nuaa/cs/index')); +router.get('/nuaa/yjsy/:type?', require('./routes/universities/nuaa/yjsy/yjsy')); // 哈尔滨工业大学 router.get('/hit/jwc', require('./routes/universities/hit/jwc')); diff --git a/lib/routes/universities/nuaa/yjsy/yjsy.js b/lib/routes/universities/nuaa/yjsy/yjsy.js new file mode 100644 index 0000000000..5c0907cd1e --- /dev/null +++ b/lib/routes/universities/nuaa/yjsy/yjsy.js @@ -0,0 +1,62 @@ +const axios = require('../../../../utils/axios'); +const cheerio = require('cheerio'); +const url = require('url'); +const host = 'http://www.graduate.nuaa.edu.cn/'; + +const map = { + latest: '2146/list.htm', + yyxw: 'yyxw/list.htm', + sjwj: 'sjwj/list.htm', + glwj: '2017/list.htm', + xxfw: '2147/list.htm', +}; + +async function load(link, ctx) { + const cache = await ctx.cache.get(link); + if (cache) { + return cache; + } + const response = await axios.get(host + link); + const $ = cheerio.load(response.data); + const images = $('img'); + for (let k = 0; k < images.length; k++) { + $(images[k]).replaceWith(``); + } + const description = $('.wp_articlecontent').html(); + await ctx.cache.set(link, description); + return { description }; +} + +module.exports = async (ctx) => { + const type = ctx.params.type || 'latest'; + const response = await axios({ + method: 'get', + url: host + map[type], + }); + const $ = cheerio.load(response.data); + const list = $('#news_list > tbody > tr > td > table > tbody > tr:nth-child(1)') + .slice(0, 10) + .get(); + const process = await Promise.all( + list.map(async (item) => { + const a = $(item).find('td:nth-child(2) > a:nth-child(2)'); + const t = $(item).find('td:nth-child(3)'); + const itemUrl = a.attr('href'); + const single = { + title: a.text(), + link: url.resolve(host, itemUrl), + guid: url.resolve(host, itemUrl), + pubDate: t.text().slice(0, 10), + }; + const other = await load(itemUrl, ctx); + return Promise.resolve(Object.assign({}, single, other)); + }) + ); + + ctx.state.data = { + title: '南航研究生院', + link: host, + description: '南航研究生院RSS', + item: process, + }; +};