From c2f2a15281bfa878e26fc3ffbd91918072fc0990 Mon Sep 17 00:00:00 2001 From: Tony Date: Tue, 21 Feb 2023 13:23:23 -0400 Subject: [PATCH] feat(route): bnu fdy (#11927) --- docs/university.md | 14 ++++++++++++++ lib/v2/bnu/fdy.js | 41 ++++++++++++++++++++++++++++++++++++++++ lib/v2/bnu/maintainer.js | 1 + lib/v2/bnu/radar.js | 8 ++++++++ lib/v2/bnu/router.js | 1 + 5 files changed, 65 insertions(+) create mode 100644 lib/v2/bnu/fdy.js diff --git a/docs/university.md b/docs/university.md index 313ffbd23..ab1019801 100644 --- a/docs/university.md +++ b/docs/university.md @@ -330,6 +330,20 @@ pageClass: routes +### 党委学生工作部辅导员发展中心 + + + +::: tip 提示 + +路径处填写对应页面 URL 中 `https://fdy.bnu.edu.cn/` 和 `/index.htm` 之间的字段。下面是一个例子。 + +若订阅 [通知公告 > 队伍建设](https://fdy.bnu.edu.cn/tzgg/dwjs/index.htm) 则将对应页面 URL 中 `https://fdy.bnu.edu.cn/` 和 `/index.htm` 之间的字段 `tzgg/dwjs` 作为路径填入。此时路由为 [`/bnu/fdy/tzgg/dwjs`](https://rsshub.app/bnu/fdy/tzgg/dwjs) + +::: + + + ## 北京物资学院 ### 通知公告 diff --git a/lib/v2/bnu/fdy.js b/lib/v2/bnu/fdy.js new file mode 100644 index 000000000..b4319f537 --- /dev/null +++ b/lib/v2/bnu/fdy.js @@ -0,0 +1,41 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const baseUrl = 'http://fdy.bnu.edu.cn'; + const { path = 'tzgg' } = ctx.params; + const link = `${baseUrl}/${path}/index.htm`; + + const { data: response } = await got(link); + const $ = cheerio.load(response); + + const list = $('.listconrl li') + .toArray() + .map((item) => { + item = $(item); + const a = item.find('a'); + return { + title: a.attr('title'), + link: new URL(a.attr('href'), link).href, + pubDate: parseDate(item.find('.news-dates').text()), + }; + }); + + 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 = $('.listconrc-newszw').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 c30e88917..f452e47d5 100644 --- a/lib/v2/bnu/maintainer.js +++ b/lib/v2/bnu/maintainer.js @@ -1,5 +1,6 @@ module.exports = { '/bs/:category?': ['nczitzk'], '/dwxgb/:category/:type': ['Fatpandac'], + '/fdy/:path*': ['TonyRL'], '/lib/:category?': ['TonyRL'], }; diff --git a/lib/v2/bnu/radar.js b/lib/v2/bnu/radar.js index c3eaf2899..ddb8a67c1 100644 --- a/lib/v2/bnu/radar.js +++ b/lib/v2/bnu/radar.js @@ -17,6 +17,14 @@ module.exports = { target: '/bnu/dwxgb/:category/:type', }, ], + fdy: [ + { + title: '党委学生工作部辅导员发展中心', + docs: 'https://docs.rsshub.app/university.html#bei-jing-shi-fan-da-xue', + source: ['/'], + target: (_, url) => `/bnu/fdy${new URL(url).pathname.replace(/\/index\.htm(l)?$/, '')}`, + }, + ], 'www.lib': [ { title: '图书馆通知', diff --git a/lib/v2/bnu/router.js b/lib/v2/bnu/router.js index 88a041368..58e357684 100644 --- a/lib/v2/bnu/router.js +++ b/lib/v2/bnu/router.js @@ -1,5 +1,6 @@ module.exports = function (router) { router.get('/bs/:category?', require('./bs')); router.get('/dwxgb/:category/:type', require('./dwxgb')); + router.get('/fdy/:path*', require('./fdy')); router.get('/lib/:category?', require('./lib')); };