From af1c20ace846ab149effcc8540d2ba7ff7e15a2a Mon Sep 17 00:00:00 2001 From: Ethan Shen <42264778+nczitzk@users.noreply.github.com> Date: Mon, 25 Sep 2023 00:35:16 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E9=87=8D=E5=BA=86?= =?UTF-8?q?=E5=B8=82=E5=9B=BD=E6=9C=89=E8=B5=84=E4=BA=A7=E7=9B=91=E7=9D=A3?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=A7=94=E5=91=98=E4=BC=9A=20(#13384)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): add 重庆市国有资产监督管理委员会 * docs: fix typo --- lib/v2/gov/chongqing/gzw.js | 68 +++++++++++++++++++++++++++++++ lib/v2/gov/maintainer.js | 1 + lib/v2/gov/radar.js | 12 ++++++ lib/v2/gov/router.js | 1 + website/docs/routes/government.md | 10 +++++ 5 files changed, 92 insertions(+) create mode 100644 lib/v2/gov/chongqing/gzw.js diff --git a/lib/v2/gov/chongqing/gzw.js b/lib/v2/gov/chongqing/gzw.js new file mode 100644 index 000000000..8098c796f --- /dev/null +++ b/lib/v2/gov/chongqing/gzw.js @@ -0,0 +1,68 @@ +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 { category = 'tzgg_191' } = ctx.params; + const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 15; + + const rootUrl = 'https://gzw.cq.gov.cn'; + const currentUrl = new URL(category, rootUrl).href; + + const { data: response } = await got(currentUrl); + + const $ = cheerio.load(response); + + let items = $('ul.tab-item li.clearfix') + .slice(0, limit) + .toArray() + .map((item) => { + item = $(item); + + const a = item.find('a'); + + return { + title: a.text(), + link: new URL(a.prop('href').replace(/^\./, category), rootUrl).href, + pubDate: parseDate(item.find('span').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('div.trs_paper_default').html(); + item.author = content('meta[name="ContentSource"]').prop('content'); + item.category = content('meta[name="Keywords"]') + .prop('content') + .split(/;/) + .filter((c) => c); + item.pubDate = timezone(parseDate(content('meta[name="PubDate"]').prop('content')), +8); + + return item; + }) + ) + ); + + const icon = new URL('favicon.ico', rootUrl).href; + + ctx.state.data = { + item: items, + title: `${$('title').text()} - ${$('meta[name="ColumnName"]').prop('content')}`, + link: currentUrl, + description: $('meta[name="ColumnDescription"]').prop('content'), + language: $('html').prop('lang'), + image: new URL($('div.logo img').prop('src'), rootUrl).href, + icon, + logo: icon, + subtitle: $('meta[name="ColumnKeywords"]').prop('content'), + author: $('meta[name="SiteName"]').prop('content'), + allowEmpty: true, + }; +}; diff --git a/lib/v2/gov/maintainer.js b/lib/v2/gov/maintainer.js index c2b921dfe..01e32681a 100644 --- a/lib/v2/gov/maintainer.js +++ b/lib/v2/gov/maintainer.js @@ -53,6 +53,7 @@ module.exports = { '/beijing/bphc/:channel': ['bigfei'], '/beijing/jw/tzgg': ['nczitzk'], '/beijing/kw/:channel': ['Fatpandac'], + '/chongqing/gzw/:category?': ['nczitzk'], '/chongqing/rsks': ['Mai19930513'], '/chongqing/sydwgkzp': ['MajexH'], '/dianbai/:path+': ['ShuiHuo'], diff --git a/lib/v2/gov/radar.js b/lib/v2/gov/radar.js index e846eeff0..43714f95b 100644 --- a/lib/v2/gov/radar.js +++ b/lib/v2/gov/radar.js @@ -444,6 +444,18 @@ module.exports = { target: '/gov/chongqing/sydwgkzp', }, ], + gzw: [ + { + title: '国有资产监督管理委员会', + docs: 'https://docs.rsshub.app/routes/government#chong-qing-shi-ren-min-zheng-fu-guo-you-zi-chan-jian-du-guan-li-wei-yuan-hui', + source: ['/:category*'], + target: (params) => { + const category = params.category; + + return `/gov/chongqing/gzw${category ? `/${category}` : ''}`; + }, + }, + ], }, 'csrc.gov.cn': { _name: '中国证券监督管理委员会', diff --git a/lib/v2/gov/router.js b/lib/v2/gov/router.js index 3ab2f03d9..33b2e9ca9 100644 --- a/lib/v2/gov/router.js +++ b/lib/v2/gov/router.js @@ -45,6 +45,7 @@ module.exports = function (router) { 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')); + router.get('/chongqing/gzw/:category*', require('./chongqing/gzw')); router.get('/chongqing/rsks', require('./chongqing/rsks')); router.get('/chongqing/sydwgkzp', require('./chongqing/sydwgkzp')); router.get(/dianbai(\/[\w/-]+)?/, require('./dianbai/dianbai')); diff --git a/website/docs/routes/government.md b/website/docs/routes/government.md index e6348b47e..a3c7e2500 100644 --- a/website/docs/routes/government.md +++ b/website/docs/routes/government.md @@ -305,6 +305,16 @@ Language ## 重庆市人民政府 {#chong-qing-shi-ren-min-zheng-fu} +### 国有资产监督管理委员会 {#chong-qing-shi-ren-min-zheng-fu-guo-you-zi-chan-jian-du-guan-li-wei-yuan-hui} + + + +| 通知公告 | 国企资讯 | 国企简介 | 国企招聘 | +| -------- | -------- | -------- | -------- | +| tzgg_191 | gqdj | gqjj | gqzp | + + + ### 两江新区信息公开网 {#chong-qing-shi-ren-min-zheng-fu-liang-jiang-xin-qu-xin-xi-gong-kai-wang} #### 党务公开 {#chong-qing-shi-ren-min-zheng-fu-liang-jiang-xin-qu-xin-xi-gong-kai-wang-dang-wu-gong-kai}