From 8e42a734011e7a4f5da0478ab9d4ce4bbbd9ff35 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sat, 27 Nov 2021 16:46:42 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E5=8C=97=E4=BA=AC?= =?UTF-8?q?=E5=A4=A7=E5=AD=A6=E4=BA=BA=E4=BA=8B=E5=A4=84=20(#8457)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/university.md | 14 +++++++++++ lib/v2/pku/hr.js | 54 ++++++++++++++++++++++++++++++++++++++++ lib/v2/pku/maintainer.js | 3 +++ lib/v2/pku/radar.js | 13 ++++++++++ lib/v2/pku/router.js | 3 +++ 5 files changed, 87 insertions(+) create mode 100644 lib/v2/pku/hr.js create mode 100644 lib/v2/pku/maintainer.js create mode 100644 lib/v2/pku/radar.js create mode 100644 lib/v2/pku/router.js 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')); +};