Skip to content

Commit

Permalink
feat(route): add 北京师范大学经济与工商管理学院 (DIYgod#8368)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan Shen authored Nov 27, 2021
1 parent 7be811e commit d82186b
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/university.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,18 @@ pageClass: routes

</Route>

## 北京师范大学

### 经济与工商管理学院

<Route author="nczitzk" example="/bnu/bs" path="/bnu/bs/:category?" :paramsDesc="['分类,见下表,默认为学院新闻']">

| 学院新闻 | 通知公告 | 学术成果 | 学术讲座 | 教师观点 | 人才招聘 |
| -------- | -------- | -------- | -------- | -------- | -------- |
| xw | zytzyyg | xzcg | xzjz | xz | bshzs |

</Route>

## 北京物资学院

### 通知公告
Expand Down
52 changes: 52 additions & 0 deletions lib/v2/bnu/bs.js
Original file line number Diff line number Diff line change
@@ -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,
};
};
3 changes: 3 additions & 0 deletions lib/v2/bnu/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/bs/:category?': ['nczitzk'],
};
13 changes: 13 additions & 0 deletions lib/v2/bnu/radar.js
Original file line number Diff line number Diff line change
@@ -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?',
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/bnu/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/bs/:category?', require('./bs'));
};

0 comments on commit d82186b

Please sign in to comment.