From d82186b99095b160953ac9a16506524bce99ca4e Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sat, 27 Nov 2021 16:33:32 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E5=8C=97=E4=BA=AC?= =?UTF-8?q?=E5=B8=88=E8=8C=83=E5=A4=A7=E5=AD=A6=E7=BB=8F=E6=B5=8E=E4=B8=8E?= =?UTF-8?q?=E5=B7=A5=E5=95=86=E7=AE=A1=E7=90=86=E5=AD=A6=E9=99=A2=20(#8368?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/university.md | 12 ++++++++++ lib/v2/bnu/bs.js | 52 ++++++++++++++++++++++++++++++++++++++++ lib/v2/bnu/maintainer.js | 3 +++ lib/v2/bnu/radar.js | 13 ++++++++++ lib/v2/bnu/router.js | 3 +++ 5 files changed, 83 insertions(+) create mode 100644 lib/v2/bnu/bs.js create mode 100644 lib/v2/bnu/maintainer.js create mode 100644 lib/v2/bnu/radar.js create mode 100644 lib/v2/bnu/router.js diff --git a/docs/university.md b/docs/university.md index 068faaa42..d998dde8a 100644 --- a/docs/university.md +++ b/docs/university.md @@ -212,6 +212,18 @@ pageClass: routes +## 北京师范大学 + +### 经济与工商管理学院 + + + +| 学院新闻 | 通知公告 | 学术成果 | 学术讲座 | 教师观点 | 人才招聘 | +| -------- | -------- | -------- | -------- | -------- | -------- | +| xw | zytzyyg | xzcg | xzjz | xz | bshzs | + + + ## 北京物资学院 ### 通知公告 diff --git a/lib/v2/bnu/bs.js b/lib/v2/bnu/bs.js new file mode 100644 index 000000000..324cdb601 --- /dev/null +++ b/lib/v2/bnu/bs.js @@ -0,0 +1,52 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const category = ctx.params.category ?? 'xw'; + + const rootUrl = 'http://bs.bnu.edu.cn'; + const currentUrl = `${rootUrl}/${category}/index.html`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('a[title]') + .map((_, item) => { + item = $(item); + + return { + title: item.attr('title'), + pubDate: parseDate(item.prev().text()), + link: `${rootUrl}/${category}/${item.attr('href')}`, + }; + }) + .get(); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + + const content = cheerio.load(detailResponse.data); + + item.description = content('.right-c-content-con').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `${$('.right-c-title').text()} - ${$('title').text()}`, + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/bnu/maintainer.js b/lib/v2/bnu/maintainer.js new file mode 100644 index 000000000..b8aaba34f --- /dev/null +++ b/lib/v2/bnu/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/bs/:category?': ['nczitzk'], +}; diff --git a/lib/v2/bnu/radar.js b/lib/v2/bnu/radar.js new file mode 100644 index 000000000..c82302c19 --- /dev/null +++ b/lib/v2/bnu/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'bnu.edu.cn': { + _name: '北京师范大学', + '.': [ + { + title: '经济与工商管理学院', + docs: 'https://docs.rsshub.app/universities.html#bei-jing-shi-fan-da-xue-jing-ji-yu-gong-shang-guan-li-xue-yuan', + source: ['/'], + target: '/bs/:category?', + }, + ], + }, +}; diff --git a/lib/v2/bnu/router.js b/lib/v2/bnu/router.js new file mode 100644 index 000000000..8435cd362 --- /dev/null +++ b/lib/v2/bnu/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/bs/:category?', require('./bs')); +};