From e399ca73c84a0f88824800760df5fa5a990d08b2 Mon Sep 17 00:00:00 2001 From: Tony Date: Fri, 19 Jan 2024 22:31:20 +0000 Subject: [PATCH] feat(route): bjedu (#14288) --- lib/v2/gov/beijing/bjedu/gh.js | 48 ++++++++++++++++++++++++++++++ lib/v2/gov/maintainer.js | 1 + lib/v2/gov/radar.js | 11 +++++++ lib/v2/gov/router.js | 1 + website/docs/routes/government.mdx | 12 ++++++++ 5 files changed, 73 insertions(+) create mode 100644 lib/v2/gov/beijing/bjedu/gh.js diff --git a/lib/v2/gov/beijing/bjedu/gh.js b/lib/v2/gov/beijing/bjedu/gh.js new file mode 100644 index 000000000..70c83a708 --- /dev/null +++ b/lib/v2/gov/beijing/bjedu/gh.js @@ -0,0 +1,48 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); + +module.exports = async (ctx) => { + const baseUrl = 'https://gh.bjedu.cn'; + const { urlPath = 'zxtzgg' } = ctx.params; + + const { data: response, url: link } = await got(`${baseUrl}/ghsite/${urlPath}/index.html`); + const $ = cheerio.load(response); + + const list = $('.content li a') + .toArray() + .map((item) => { + item = $(item); + return { + title: item.text().trim(), + link: item.attr('href').startsWith('http') ? item.attr('href').replace(/^http:/, 'https:') : new URL(item.attr('href'), link).href, + pubDate: item.prev().length ? timezone(parseDate(item.prev().text().trim(), 'YYYY-MM-DD'), +8) : null, + }; + }); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + if (!item.link.endsWith('.html')) { + return item; + } + const { data: response } = await got(item.link); + const $ = cheerio.load(response); + + item.title = item.title.endsWith('...') ? $('.con-h h1').text().trim() : item.title; + item.pubDate = timezone(parseDate($('.con-h span').eq(0).text().trim(), 'YYYY-MM-DD HH:mm:ss'), +8); + item.author = $('.con-h span').eq(1).text().trim(); + item.description = $('.content_font').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('head title').text(), + link, + item: items, + }; +}; diff --git a/lib/v2/gov/maintainer.js b/lib/v2/gov/maintainer.js index ad148d8cd..518fceab0 100644 --- a/lib/v2/gov/maintainer.js +++ b/lib/v2/gov/maintainer.js @@ -69,6 +69,7 @@ module.exports = { '/zhengce/:category?': ['nczitzk'], // province '/anhui/kjt/:path?': ['nczitzk'], + '/beijing/bjedu/gh/:urlPath?': ['TonyRL'], '/beijing/bphc/:channel': ['bigfei'], '/beijing/jw/tzgg': ['nczitzk'], '/beijing/kw/:channel': ['Fatpandac'], diff --git a/lib/v2/gov/radar.js b/lib/v2/gov/radar.js index fdbe9addc..b5fea4cbc 100644 --- a/lib/v2/gov/radar.js +++ b/lib/v2/gov/radar.js @@ -297,6 +297,17 @@ module.exports = { }, ], }, + 'bjedu.gov.cn': { + _name: '北京市教育委员会', + gh: [ + { + title: '教育科学规划网 - 通用', + docs: 'https://docs.rsshub.app/routes/government#bei-jing-shi-jiao-yu-ke-xue-gui-hua-wang', + source: ['/ghsite/:urlPath/index.html', '/ghsite/:urlPath'], + target: '/gov/beijing/bjedu/gh/:urlPath', + }, + ], + }, 'bphc.com.cn': { _name: '北京保障房中心有限公司', gycpt: [ diff --git a/lib/v2/gov/router.js b/lib/v2/gov/router.js index 8ba768d78..2b93e2659 100644 --- a/lib/v2/gov/router.js +++ b/lib/v2/gov/router.js @@ -62,6 +62,7 @@ module.exports = function (router) { router.get('/zhengce/:category*', require('./zhengce')); // province router.get(/anhui\/kjt\/([\w/-]+)?/, require('./anhui/kjt')); + router.get('/beijing/bjedu/gh/:urlPath?', require('./beijing/bjedu/gh')); router.get(/beijing\/bphc(\/[\w/-]+)?/, require('./beijing/bphc')); router.get('/beijing/jw/tzgg', require('./beijing/jw/tzgg')); router.get('/beijing/kw/:channel', require('./beijing/kw/index')); diff --git a/website/docs/routes/government.mdx b/website/docs/routes/government.mdx index 4af11ad30..439595e4b 100644 --- a/website/docs/routes/government.mdx +++ b/website/docs/routes/government.mdx @@ -224,6 +224,18 @@ | announcement | project | +## 北京市教育科学规划网 {#bei-jing-shi-jiao-yu-ke-xue-gui-hua-wang} + +### 通用 {#bei-jing-shi-jiao-yu-ke-xue-gui-hua-wang-tong-yong} + + + :::tip + 路径处填写对应页面 URL 中 `https://gh.bjedu.cn/ghsite/` 和 `/index.html` 之间的字段。下面是一个例子。 + + 若订阅 [通知公告](https://gh.bjedu.cn/ghsite/zxtzgg/index.html) 则将对应页面 URL `https://gh.bjedu.cn/ghsite/zxtzgg/index.html` 中 `https://gh.bjedu.cn/ghsite/` 和 `/index.html` 之间的字段 `zxtzgg` 作为路径填入。此时路由为 [`/gov/beijing/bjedu/gh/zxtzgg`](https://rsshub.app/gov/beijing/bjedu/gh/zxtzgg) + ::: + + ## 北京市教育委员会 {#bei-jing-shi-jiao-yu-wei-yuan-hui} ### 通知公告 {#bei-jing-shi-jiao-yu-wei-yuan-hui-tong-zhi-gong-gao}