From 9bccbc2c922b16ff4d333ee89cb3916c010a9d1c Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Tue, 12 May 2020 14:25:29 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E8=A5=BF=E5=AE=89=E4=BA=A4?= =?UTF-8?q?=E9=80=9A=E5=A4=A7=E5=AD=A6=E7=A0=94=E7=A9=B6=E7=94=9F=E9=99=A2?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E5=85=AC=E5=91=8A=20(#4748)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/university.md | 4 +++ lib/router.js | 1 + lib/routes/universities/xjtu/gs/tzgg.js | 40 +++++++++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 lib/routes/universities/xjtu/gs/tzgg.js diff --git a/docs/university.md b/docs/university.md index ddcab3f38..e438fa0d4 100644 --- a/docs/university.md +++ b/docs/university.md @@ -1369,6 +1369,10 @@ type 列表: +### 研究生院通知公告 + + + ::: tip 提示 支持`http://dean.xjtu.edu.cn/`下所有**有文章列表**的栏目, diff --git a/lib/router.js b/lib/router.js index e83204351..f7f96ab26 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2406,6 +2406,7 @@ router.get('/wolley/user/:id', require('./routes/wolley/user')); 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')); // booksource diff --git a/lib/routes/universities/xjtu/gs/tzgg.js b/lib/routes/universities/xjtu/gs/tzgg.js new file mode 100644 index 000000000..01aab16c5 --- /dev/null +++ b/lib/routes/universities/xjtu/gs/tzgg.js @@ -0,0 +1,40 @@ +const url = require('url'); +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const rootUrl = 'http://gs.xjtu.edu.cn/tzgg.htm'; + const response = await got({ + method: 'get', + url: rootUrl, + }); + const $ = cheerio.load(response.data); + const list = $('div.list_right_con ul li') + .slice(0, 10) + .map((_, item) => { + item = $(item); + const a = item.find('a'); + return { + title: a.text(), + link: url.resolve('http://gs.xjtu.edu.cn/', a.attr('href')), + pubDate: new Date(item.find('span.time').text()).toUTCString(), + }; + }) + .get(); + + ctx.state.data = { + title: '西安交通大学研究生院 - 通知公告', + link: rootUrl, + item: await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const res = await got({ method: 'get', url: item.link }); + const content = cheerio.load(res.data); + item.description = content('#vsb_content').html(); + return item; + }) + ) + ), + }; +};