diff --git a/docs/README.md b/docs/README.md index 7b2200103f..942feeb495 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1268,7 +1268,11 @@ GitHub 官方也提供了一些 RSS: - + + +| 通知公告 | 新闻动态 | 科研动态 | 教学动态 | 学生工作 | 招生信息 | 就业信息 | +| -------- | -------- | -------- | -------- | -------- | -------- | -------- | +| tzgg | xwdt | kydt | jxdt | xsgz | zsxx | jyxx | ### 哈尔滨工业大学 diff --git a/router.js b/router.js index 3b06be580d..bf056eb87c 100644 --- a/router.js +++ b/router.js @@ -540,7 +540,7 @@ router.get('/seu/yzb/:type', require('./routes/universities/seu/yzb')); // 南京航空航天大学 router.get('/nuaa/jwc/:type?', require('./routes/universities/nuaa/jwc/jwc')); -router.get('/nuaa/cs/academic', require('./routes/universities/nuaa/cs/academic')); +router.get('/nuaa/cs/:type?', require('./routes/universities/nuaa/cs/index')); // 哈尔滨工业大学 router.get('/hit/jwc', require('./routes/universities/hit/jwc')); diff --git a/routes/universities/nuaa/cs/academic.js b/routes/universities/nuaa/cs/academic.js deleted file mode 100644 index a058f0d514..0000000000 --- a/routes/universities/nuaa/cs/academic.js +++ /dev/null @@ -1,64 +0,0 @@ -const axios = require('../../../../utils/axios'); -const cheerio = require('cheerio'); -const url = require('url'); - -const host = 'http://cs.nuaa.edu.cn/'; - -module.exports = async (ctx) => { - const link = url.resolve(host, '1975/list.htm'); - const response = await axios.get(link); - const $ = cheerio.load(response.data); - - const list = $('tr.section') - .slice(0, 10) - .map(function() { - const info = { - title: $(this) - .find('td:nth-child(2) a') - .attr('title'), - link: $(this) - .find('td:nth-child(2) a') - .attr('href'), - date: $(this) - .find('td:nth-child(3)') - .text(), - }; - return info; - }) - .get(); - - const out = await Promise.all( - list.map(async (info) => { - const title = info.title; - const date = info.date; - const itemUrl = url.resolve(host, info.link); - - 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 single = { - title: title, - link: itemUrl, - description: $('.wp_articlecontent') - .html() - .replace(/src="\//g, `src="${url.resolve(host, '.')}`) - .trim(), - pubDate: new Date(date), - }; - ctx.cache.set(itemUrl, JSON.stringify(single), 24 * 60 * 60); - return Promise.resolve(single); - }) - ); - - ctx.state.data = { - title: '南航计算机科学与技术学院学术讲座', - link: link, - description: '南航计算机科学与技术学院学术讲座RSS', - item: out, - }; -}; diff --git a/routes/universities/nuaa/cs/index.js b/routes/universities/nuaa/cs/index.js new file mode 100644 index 0000000000..36dc96413d --- /dev/null +++ b/routes/universities/nuaa/cs/index.js @@ -0,0 +1,84 @@ +const axios = require('../../../../utils/axios'); +const cheerio = require('cheerio'); +const url = require('url'); + +const host = 'http://cs.nuaa.edu.cn/'; + +const map = new Map([ + ['tzgg', { title: '南京航空航天大学计算机科学与技术学院 -- 通知公告', suffix: '1995/list.htm' }], + ['xwdt', { title: '南京航空航天大学计算机科学与技术学院 -- 新闻动态', suffix: '1997/list.htm' }], + ['kydt', { title: '南京航空航天大学计算机科学与技术学院 -- 科研动态', suffix: '1975/list.htm' }], + ['jxdt', { title: '南京航空航天大学计算机科学与技术学院 -- 教学动态', suffix: '1977/list.htm' }], + ['xsgz', { title: '南京航空航天大学计算机科学与技术学院 -- 学生工作', suffix: '1959/list.htm' }], + ['zsxx', { title: '南京航空航天大学计算机科学与技术学院 -- 招生信息', suffix: '1993/list.htm' }], + ['jyxx', { title: '南京航空航天大学计算机科学与技术学院 -- 就业信息', suffix: '1994/list.htm' }], +]); + +module.exports = async (ctx) => { + const type = ctx.params.type || 'tzgg'; + const suffix = map.get(type).suffix; + + const link = url.resolve(host, suffix); + const response = await axios.get(link); + const $ = cheerio.load(response.data); + + const list = $('tr.section') + .slice(0, 10) + .map(function() { + const info = { + title: $(this) + .find('td:nth-child(2) a') + .attr('title'), + link: $(this) + .find('td:nth-child(2) a') + .attr('href'), + date: $(this) + .find('td:nth-child(3)') + .text(), + }; + return info; + }) + .get(); + + const out = await Promise.all( + list.map(async (info) => { + const title = info.title || 'tzgg'; + const date = info.date; + const itemUrl = url.resolve(host, info.link); + + const cache = await ctx.cache.get(itemUrl); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + + const arr = itemUrl.split('.'); + const pageType = arr[arr.length - 1]; + + let description = itemUrl; + if (pageType === 'htm' || pageType === 'html') { + const response = await axios.get(itemUrl); + const $ = cheerio.load(response.data); + description = $('.wp_articlecontent') + .html() + .replace(/src="\//g, `src="${url.resolve(host, '.')}`) + .trim(); + } + + const single = { + title: title, + link: itemUrl, + description: description, + pubDate: new Date(date), + }; + ctx.cache.set(itemUrl, JSON.stringify(single), 24 * 60 * 60); + return Promise.resolve(single); + }) + ); + + ctx.state.data = { + title: map.get(type).title, + link: link, + description: '南京航空航天大学计算机科学与技术学院RSS', + item: out, + }; +};