From dd0c1a32f29db2f7db271060ea239f37390210a7 Mon Sep 17 00:00:00 2001 From: Tony Date: Tue, 21 Feb 2023 10:57:18 -0400 Subject: [PATCH] feat(route): bnu lib (#11925) --- docs/university.md | 20 +++++++++++++++----- lib/v2/bnu/lib.js | 40 ++++++++++++++++++++++++++++++++++++++++ lib/v2/bnu/maintainer.js | 2 ++ lib/v2/bnu/radar.js | 20 +++++++++++++++----- lib/v2/bnu/router.js | 1 + 5 files changed, 73 insertions(+), 10 deletions(-) create mode 100644 lib/v2/bnu/lib.js diff --git a/docs/university.md b/docs/university.md index f84976da0d..313ffbd239 100644 --- a/docs/university.md +++ b/docs/university.md @@ -278,6 +278,16 @@ pageClass: routes +### 信息学院通知 + + + +| 学院新闻 | 科研动态 | 本科生培养 | 研究生培养 | +| ---- | ---- | ----- | ----- | +| xyxw | kydt | pydt | pydt2 | + + + ### 教务处通知公告 @@ -310,13 +320,13 @@ pageClass: routes -### 信息学院通知 +### 图书馆通知 - + -| 学院新闻 | 科研动态 | 本科生培养 | 研究生培养 | -| ---- | ---- | ----- | ----- | -| xyxw | kydt | pydt | pydt2 | +| 资源动态 | 新闻动态 | 系列讲座 | +| ---- | ---- | ----- | +| zydt | xwdt | xljz1 | diff --git a/lib/v2/bnu/lib.js b/lib/v2/bnu/lib.js new file mode 100644 index 0000000000..0ef008ba92 --- /dev/null +++ b/lib/v2/bnu/lib.js @@ -0,0 +1,40 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const baseUrl = 'http://www.lib.bnu.edu.cn'; + const { category = 'zydt' } = ctx.params; + const link = `${baseUrl}/${category}/index.htm`; + + const { data: response } = await got(link); + const $ = cheerio.load(response); + + const list = $('.view-content .item-list li') + .toArray() + .map((item) => { + item = $(item); + return { + title: item.find('a').text(), + link: `${baseUrl}/${category}/${item.find('a').attr('href')}`, + pubDate: parseDate(item.find('span > span').eq(1).text(), 'YYYY-MM-DD'), + }; + }); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const { data: response } = await got(item.link); + const $ = cheerio.load(response); + item.description = $('#block-system-main .content .content').html(); + return item; + }) + ) + ); + + ctx.state.data = { + title: $('head title').text(), + link, + item: items, + }; +}; diff --git a/lib/v2/bnu/maintainer.js b/lib/v2/bnu/maintainer.js index b8aaba34f6..c30e889173 100644 --- a/lib/v2/bnu/maintainer.js +++ b/lib/v2/bnu/maintainer.js @@ -1,3 +1,5 @@ module.exports = { '/bs/:category?': ['nczitzk'], + '/dwxgb/:category/:type': ['Fatpandac'], + '/lib/:category?': ['TonyRL'], }; diff --git a/lib/v2/bnu/radar.js b/lib/v2/bnu/radar.js index 471cb5c959..c3eaf28990 100644 --- a/lib/v2/bnu/radar.js +++ b/lib/v2/bnu/radar.js @@ -1,19 +1,29 @@ module.exports = { 'bnu.edu.cn': { _name: '北京师范大学', - '.': [ + bs: [ { title: '经济与工商管理学院', docs: 'https://docs.rsshub.app/university.html#bei-jing-shi-fan-da-xue', - source: ['/'], - target: '/bs/:category?', + source: ['/:category/index.html'], + target: '/bnu/bs/:category', }, + ], + dwxgb: [ { - title: '经济与工商管理学院', + title: '党委学生工作部', docs: 'https://docs.rsshub.app/university.html#bei-jing-shi-fan-da-xue', - source: ['/'], + source: ['/:category/:type/index.html'], target: '/bnu/dwxgb/:category/:type', }, ], + 'www.lib': [ + { + title: '图书馆通知', + docs: 'https://docs.rsshub.app/university.html#bei-jing-shi-fan-da-xue', + source: ['/:category/index.htm'], + target: '/bnu/lib/:category', + }, + ], }, }; diff --git a/lib/v2/bnu/router.js b/lib/v2/bnu/router.js index e605fe286d..88a0413684 100644 --- a/lib/v2/bnu/router.js +++ b/lib/v2/bnu/router.js @@ -1,4 +1,5 @@ module.exports = function (router) { router.get('/bs/:category?', require('./bs')); router.get('/dwxgb/:category/:type', require('./dwxgb')); + router.get('/lib/:category?', require('./lib')); };