diff --git a/docs/university.md b/docs/university.md index d7f2d6dd10..e75cbf97dd 100644 --- a/docs/university.md +++ b/docs/university.md @@ -1076,6 +1076,24 @@ https://rsshub.app/**nuist**/`bulletin` 或 https://rsshub.app/**nuist**/`bullet +## 西安交通大学 + +### 教务处 + + + +::: tip 提示 + +支持`http://dean.xjtu.edu.cn/`下所有**有文章列表**的栏目, + +例如`http://dean.xjtu.edu.cn/gzlc.htm`, 则`subpath`为`gzlc` + +又例`http://dean.xjtu.edu.cn/jxxx/xytz.htm`, 则`subpath`为`jxxx/xytz` + +::: + + + ## 西南财经大学 ### 经济信息工程学院 diff --git a/lib/router.js b/lib/router.js index f86ed050b3..9a2ec7ed6c 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2307,4 +2307,7 @@ router.get('/magireco/event_banner', require('./routes/magireco/event_banner')); // wolley router.get('/wolley', require('./routes/wolley/index')); +// 西安交大 +router.get('/xjtu/dean/:subpath+', require('./routes/universities/xjtu/dean')); + module.exports = router; diff --git a/lib/routes/universities/xjtu/dean.js b/lib/routes/universities/xjtu/dean.js new file mode 100644 index 0000000000..f753678d99 --- /dev/null +++ b/lib/routes/universities/xjtu/dean.js @@ -0,0 +1,91 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const subpath = ctx.params.subpath; + + const url = `http://dean.xjtu.edu.cn/${subpath.replace(/\.htm/g, '')}.htm`; + const base = url + .split('/') + .slice(0, -1) + .join('/'); + + const list_response = await got.get(url); + const $ = cheerio.load(list_response.data); + + const subname = $('em.ma-nav a') + .slice(1) + .map(function() { + return $(this).text(); + }) + .get() + .join(' - '); + + const list = $('.list_main_content > .list-li').get(); + + const parseContent = async (htmlString) => { + const $ = cheerio.load(htmlString); + + const info = $('.detail_main_content > h1') + .contents() + .filter(function() { + return this.nodeType === 3; + }) + .map(function() { + return $(this) + .text() + .trim(); + }) + .get(); + + const content = $('[id^="vsb_content"]'); + $('form > div > ul a').each(function() { + $(this).appendTo(content); + $('
').appendTo(content); + }); + + return { + author: info[0] || '教务处', + description: content.html(), + pubDate: new Date(info[1]), + }; + }; + + const out = await Promise.all( + list.map(async (item) => { + const $ = cheerio.load(item); + + const title = $('a'); + const link = new URL(title.attr('href'), base); + + const cache = await ctx.cache.get(link); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + + const rssitem = { + title: title.text().trim(), + link: link, + }; + + try { + const response = await got.get(link); + const result = await parseContent(response.data); + + rssitem.description = result.description; + rssitem.author = result.author; + rssitem.pubDate = result.pubDate; + } catch (err) { + return Promise.resolve(''); + } + ctx.cache.set(link, JSON.stringify(rssitem)); + return Promise.resolve(rssitem); + }) + ); + + ctx.state.data = { + title: `西安交大教务处 - ${subname}`, + link: url, + item: out.filter((item) => item !== ''), + }; +};