From e8310889fbdd6c72adde5af58889ec0d03278908 Mon Sep 17 00:00:00 2001 From: Ethan Shen <42264778+nczitzk@users.noreply.github.com> Date: Fri, 15 Dec 2023 01:50:29 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E5=9B=BD=E5=AE=B6?= =?UTF-8?q?=E8=83=BD=E6=BA=90=E5=B1=80=E5=8F=91=E5=B1=95=E8=A7=84=E5=88=92?= =?UTF-8?q?=E5=8F=B8=20(#14039)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/v2/gov/maintainer.js | 1 + lib/v2/gov/nea/ghs.js | 58 ++++++++++++++++++++++++++++++ lib/v2/gov/radar.js | 11 ++++++ lib/v2/gov/router.js | 1 + website/docs/routes/government.mdx | 6 ++++ 5 files changed, 77 insertions(+) create mode 100644 lib/v2/gov/nea/ghs.js diff --git a/lib/v2/gov/maintainer.js b/lib/v2/gov/maintainer.js index b5bf37a17c..62c6eca82d 100644 --- a/lib/v2/gov/maintainer.js +++ b/lib/v2/gov/maintainer.js @@ -36,6 +36,7 @@ module.exports = { '/mofcom/article/:suffix+': ['LogicJake'], '/moj/aac/news/:type?': ['TonyRL'], '/mot/:category?': ['nczitzk'], + '/nea/sjzz/ghs': ['nczitzk'], '/news/:uid': ['EsuRt'], '/nifdc/:path?': ['nczitzk'], '/nmpa/:path+': ['TonyRL'], diff --git a/lib/v2/gov/nea/ghs.js b/lib/v2/gov/nea/ghs.js new file mode 100644 index 0000000000..ada796886b --- /dev/null +++ b/lib/v2/gov/nea/ghs.js @@ -0,0 +1,58 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const timezone = require('@/utils/timezone'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 35; + + const rootUrl = 'https://www.nea.gov.cn'; + const currentUrl = new URL('sjzz/ghs/', rootUrl).href; + + const { data: response } = await got(currentUrl); + + const $ = cheerio.load(response); + + let items = $('div.right_box ul li') + .slice(0, limit) + .toArray() + .map((item) => { + item = $(item); + + const a = item.find('a'); + + return { + title: a.text(), + link: a.prop('href'), + pubDate: parseDate(item.find('span.date-tex').text()), + }; + }); + + items = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const { data: detailResponse } = await got(item.link); + + const content = cheerio.load(detailResponse); + + item.title = content('meta[name="ArticleTitle"]').prop('content'); + item.description = content('td.detail').html() || content('div.article-content td').html(); + item.author = content('meta[name="ContentSource"]').prop('content'); + item.category = content('meta[name="keywords"]').prop('content').split(/,/); + item.pubDate = timezone(parseDate(content('meta[name="PubDate"]').prop('content')), +8); + + return item; + }) + ) + ); + + ctx.state.data = { + item: items, + title: $('title').text(), + link: currentUrl, + description: $('meta[name="ColumnDescription"]').prop('content'), + language: 'zh', + subtitle: $('meta[name="ColumnType"]').prop('content'), + author: $('meta[name="ColumnKeywords"]').prop('content'), + }; +}; diff --git a/lib/v2/gov/radar.js b/lib/v2/gov/radar.js index 99ccc68070..18802a66d3 100644 --- a/lib/v2/gov/radar.js +++ b/lib/v2/gov/radar.js @@ -1048,6 +1048,17 @@ module.exports = { }, ], }, + 'nea.gov.cn': { + _name: '国家能源局', + '.': [ + { + title: '发展规划司', + docs: 'https://docs.rsshub.app/routes/government#guo-jia-neng-yuan-ju-fa-zhan-gui-hua-si', + source: ['/sjzz/ghs/'], + target: '/gov/nea/sjzz/ghs', + }, + ], + }, 'nifdc.gov.cn': { _name: '国家药品监督管理局医疗器械标准管理中心', '.': [ diff --git a/lib/v2/gov/router.js b/lib/v2/gov/router.js index 2f93ef4edb..f0b1b7d213 100644 --- a/lib/v2/gov/router.js +++ b/lib/v2/gov/router.js @@ -29,6 +29,7 @@ module.exports = function (router) { router.get('/moe/s78/:column', require('./moe/s78')); router.get('/mofcom/article/:suffix+', require('./mofcom/article')); router.get('/moj/aac/news/:type?', require('./moj/aac/news')); + router.get('/nea/sjzz/ghs', require('./nea/ghs')); router.get('/news/:uid', require('./news')); router.get('/nifdc/:path*', require('./nifdc')); router.get(/\/nmpa\/([\w][\w/]+)?/, require('./nmpa/generic')); diff --git a/website/docs/routes/government.mdx b/website/docs/routes/government.mdx index 0ac221e56e..784f61082e 100644 --- a/website/docs/routes/government.mdx +++ b/website/docs/routes/government.mdx @@ -423,6 +423,12 @@ | 其他 | qt | +## 国家能源局 {#guo-jia-neng-yuan-ju} + +### 发展规划司 {#guo-jia-neng-yuan-ju-fa-zhan-gui-hua-si} + + + ## 国家市场监督管理总局 {#guo-jia-shi-chang-jian-du-guan-li-zong-ju} ### 留言咨询 {#guo-jia-shi-chang-jian-du-guan-li-zong-ju-liu-yan-zi-xun}