feat(route): add 北京大学人事处 (#8457)

This commit is contained in:
Ethan Shen 2021-11-27 16:46:42 +08:00 committed by GitHub
parent 2024ba9108
commit 8e42a73401
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 87 additions and 0 deletions

View File

@ -136,6 +136,20 @@ pageClass: routes
</Route>
### 人事处
<Route author="nczitzk" example="/pku/hr" path="/pku/hr/:category?" :paramsDesc="['分类,见下方说明,默认为首页最新公告']">
::: tip 提示
分类字段处填写的是对应北京大学人事处分类页网址中介于 **<http://hr.pku.edu.cn/>** 和 **/index.htm** 中间的一段,并将其中的 `/` 修改为 `-`
如 [北京大学人事处 - 人才招聘 - 教师 - 教学科研人员](https://hr.pku.edu.cn/rczp/js/jxkyry/index.htm) 的网址为 <https://hr.pku.edu.cn/rczp/js/jxkyry/index.htm> 其中介于 **<http://hr.pku.edu.cn/>** 和 **/index.htm** 中间的一段为 `rczp/js/jxkyry`。随后,并将其中的 `/` 修改为 `-`,可以得到 `rczp-js-jxkyry`。所以最终我们的路由为 [`/pku/hr/rczp-js-jxkyry`](https://rsshub.app/pku/hr/rczp-js-jxkyry)
:::
</Route>
## 北京航空航天大学
### 北京航空航天大学

54
lib/v2/pku/hr.js Normal file
View File

@ -0,0 +1,54 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const category = ctx.params.category?.replace(/-/g, '/') ?? 'zxgg';
const rootUrl = 'https://hr.pku.edu.cn/';
const currentUrl = `${rootUrl}/${category}/index.htm`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('.item-list li a')
.map((_, item) => {
item = $(item);
return {
title: item.text().replace(/\d+、/, ''),
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);
content('.title').remove();
item.description = content('.article').html();
item.pubDate = parseDate(content('#date').text());
return item;
})
)
);
ctx.state.data = {
title: `${$('h2').text()} - ${$('title').text()}`,
link: currentUrl,
item: items,
};
};

3
lib/v2/pku/maintainer.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = {
'/hr/:category?': ['nczitzk'],
};

13
lib/v2/pku/radar.js Normal file
View File

@ -0,0 +1,13 @@
module.exports = {
'pku.edu.cn': {
_name: '北京大学',
hr: [
{
title: '人事处',
docs: 'https://docs.rsshub.app/university.html#bei-jing-da-xue-ren-shi-chu',
source: ['/'],
target: '/pku/hr/:category?',
},
],
},
};

3
lib/v2/pku/router.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/hr/:category?', require('./hr'));
};