Skip to content

Commit

Permalink
feat(route): bnu fdy (DIYgod#11927)
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyRL authored Feb 21, 2023
1 parent 4ca2c8c commit c2f2a15
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 0 deletions.
14 changes: 14 additions & 0 deletions docs/university.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,20 @@ pageClass: routes

</Route>

### 党委学生工作部辅导员发展中心

<Route author="TonyRL" example="/bnu/fdy/tzgg/dwjs" path="/bnu/fdy/:path*" :paramsDesc="['路径,默认为 `tzgg`']" radar="1">

::: tip 提示

路径处填写对应页面 URL 中 `https://fdy.bnu.edu.cn/``/index.htm` 之间的字段。下面是一个例子。

若订阅 [通知公告 > 队伍建设](https://fdy.bnu.edu.cn/tzgg/dwjs/index.htm) 则将对应页面 URL <https://fdy.bnu.edu.cn/tzgg/dwjs/index.htm>`https://fdy.bnu.edu.cn/``/index.htm` 之间的字段 `tzgg/dwjs` 作为路径填入。此时路由为 [`/bnu/fdy/tzgg/dwjs`](https://rsshub.app/bnu/fdy/tzgg/dwjs)

:::

</Route>

## 北京物资学院

### 通知公告
Expand Down
41 changes: 41 additions & 0 deletions lib/v2/bnu/fdy.js
Original file line number Diff line number Diff line change
@@ -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,
};
};
1 change: 1 addition & 0 deletions lib/v2/bnu/maintainer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = {
'/bs/:category?': ['nczitzk'],
'/dwxgb/:category/:type': ['Fatpandac'],
'/fdy/:path*': ['TonyRL'],
'/lib/:category?': ['TonyRL'],
};
8 changes: 8 additions & 0 deletions lib/v2/bnu/radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '图书馆通知',
Expand Down
1 change: 1 addition & 0 deletions lib/v2/bnu/router.js
Original file line number Diff line number Diff line change
@@ -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'));
};

0 comments on commit c2f2a15

Please sign in to comment.