diff --git a/docs/university.md b/docs/university.md index a6d37cf02..19022727e 100644 --- a/docs/university.md +++ b/docs/university.md @@ -136,6 +136,20 @@ pageClass: routes +### 人事处 + + + +::: tip 提示 + +分类字段处填写的是对应北京大学人事处分类页网址中介于 **** 和 **/index.htm** 中间的一段,并将其中的 `/` 修改为 `-`。 + +如 [北京大学人事处 - 人才招聘 - 教师 - 教学科研人员](https://hr.pku.edu.cn/rczp/js/jxkyry/index.htm) 的网址为 其中介于 **** 和 **/index.htm** 中间的一段为 `rczp/js/jxkyry`。随后,并将其中的 `/` 修改为 `-`,可以得到 `rczp-js-jxkyry`。所以最终我们的路由为 [`/pku/hr/rczp-js-jxkyry`](https://rsshub.app/pku/hr/rczp-js-jxkyry) + +::: + + + ## 北京航空航天大学 ### 北京航空航天大学 diff --git a/lib/v2/pku/hr.js b/lib/v2/pku/hr.js new file mode 100644 index 000000000..a2be6f5f4 --- /dev/null +++ b/lib/v2/pku/hr.js @@ -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, + }; +}; diff --git a/lib/v2/pku/maintainer.js b/lib/v2/pku/maintainer.js new file mode 100644 index 000000000..de641d1c6 --- /dev/null +++ b/lib/v2/pku/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/hr/:category?': ['nczitzk'], +}; diff --git a/lib/v2/pku/radar.js b/lib/v2/pku/radar.js new file mode 100644 index 000000000..5de8bc529 --- /dev/null +++ b/lib/v2/pku/radar.js @@ -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?', + }, + ], + }, +}; diff --git a/lib/v2/pku/router.js b/lib/v2/pku/router.js new file mode 100644 index 000000000..6f22cd81e --- /dev/null +++ b/lib/v2/pku/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/hr/:category?', require('./hr')); +};