From 5e7c3fcf555d2c818dbc46329941848559e66344 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AC=A0=E9=99=A5=E9=9B=BB=E6=B0=97?= Date: Tue, 27 Jun 2023 21:00:03 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E4=B8=AD=E5=9B=BD?= =?UTF-8?q?=E7=A7=91=E5=AD=A6=E9=99=A2=E8=BD=AF=E4=BB=B6=E7=A0=94=E7=A9=B6?= =?UTF-8?q?=E6=89=80=20(#12719)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): add 中国科学院软件研究所 * fix(route): fix Incomplete URL substring sanitization --------- --- docs/university.md | 12 +++++++++++ lib/v2/cas/is/index.js | 44 ++++++++++++++++++++++++++++++++++++++++ lib/v2/cas/maintainer.js | 1 + lib/v2/cas/radar.js | 12 +++++++++++ lib/v2/cas/router.js | 1 + 5 files changed, 70 insertions(+) create mode 100644 lib/v2/cas/is/index.js diff --git a/docs/university.md b/docs/university.md index fca9af2e8..915850ecb 100644 --- a/docs/university.md +++ b/docs/university.md @@ -3713,6 +3713,18 @@ jsjxy.hbut.edu.cn 证书链不全,自建 RSSHub 可设置环境变量 NODE_TLS +### 软件研究所 + + + +路径参数示例: + +| 通知公告 | 科技动态 | 科普动态 | +| ----------------- | ----------------- | ----------------- | +| xwdt2016/tzgg2016 | xwdt2016/kjdt2016 | kxcb2016/kpdt2016 | + + + ## 中国科学院大学 ### 招聘信息 diff --git a/lib/v2/cas/is/index.js b/lib/v2/cas/is/index.js new file mode 100644 index 000000000..aa9cc8eeb --- /dev/null +++ b/lib/v2/cas/is/index.js @@ -0,0 +1,44 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +const baseUrl = 'https://is.cas.cn'; + +module.exports = async (ctx) => { + const { path } = ctx.params; + const response = await got(`${baseUrl}/${path}/`); + + const $ = cheerio.load(response.data); + const items = $('.list-news ul li') + .toArray() + .map((item) => { + item = $(item); + return { + title: item.find('a').text(), + link: new URL(item.find('a').attr('href'), response.url).href, + pubDate: parseDate(item.find('span').text().replace(/\[|\]/g, '')), + }; + }); + + await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + if (!item.link.startsWith(`${baseUrl}/`)) { + return item; + } + + const response = await got(item.link); + const $ = cheerio.load(response.data); + + item.description = $('.TRS_Editor').html(); + return item; + }) + ) + ); + + ctx.state.data = { + title: $('head title').text(), + link: `${baseUrl}/${path}`, + item: items, + }; +}; diff --git a/lib/v2/cas/maintainer.js b/lib/v2/cas/maintainer.js index ca5f4fef7..04d0e7d92 100644 --- a/lib/v2/cas/maintainer.js +++ b/lib/v2/cas/maintainer.js @@ -2,6 +2,7 @@ module.exports = { '/cg/:caty?': ['nczitzk'], '/ia/yjs': ['shengmaosu'], '/iee/kydt': ['nczitzk'], + '/is/:path+': ['Misaka13514'], '/mesalab/kb': ['renzhexigua'], '/sim/kyjz': ['HenryQW'], }; diff --git a/lib/v2/cas/radar.js b/lib/v2/cas/radar.js index 5f849361c..3696b746f 100644 --- a/lib/v2/cas/radar.js +++ b/lib/v2/cas/radar.js @@ -17,6 +17,18 @@ module.exports = { target: '/cas/ia/yjs', }, ], + 'www.is': [ + { + title: '软件研究所', + docs: 'https://docs.rsshub.app/university.html#zhong-guo-ke-xue-yuan', + source: ['/'], + target: (params, url, document) => { + if (document.querySelector('.list-news')) { + return `/cas/is/${url.split('/').slice(3, -1).join('/')}`; + } + } + }, + ], 'www.sim': [ { title: '上海微系统与信息技术研究所 - 科技进展', diff --git a/lib/v2/cas/router.js b/lib/v2/cas/router.js index adf2c80e0..fe4e5f49c 100644 --- a/lib/v2/cas/router.js +++ b/lib/v2/cas/router.js @@ -2,6 +2,7 @@ module.exports = (router) => { router.get('/cg/:caty?', require('./cg/index')); router.get('/ia/yjs', require('./ia/yjs')); router.get('/iee/kydt', require('./iee/kydt')); + router.get('/is/:path+', require('./is/index')); router.get('/mesalab/kb', require('./mesalab/kb')); router.get('/sim/kyjz', require('./sim/kyjz')); };