From 51ec49d0de567fde04c3783fb4fa6f933aace734 Mon Sep 17 00:00:00 2001 From: drgnchan <40224023+drgnchan@users.noreply.github.com> Date: Thu, 8 Dec 2022 01:15:00 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20=E6=96=B0=E5=A2=9E=E5=B9=BF?= =?UTF-8?q?=E5=B7=9E=E5=B8=82=E4=BA=BA=E6=B0=91=E6=94=BF=E5=BA=9C=20(#1133?= =?UTF-8?q?9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat[route]: 新增广州市人民政府 * fix(v2ex): enable allowEmpty and enrich pubDate * refactor: move `gzgov` dir under `gov` * refactor: replace `gzgov` by `gz` and change doc accordingly * refactor: polish code * refactor: polish code * fix: maintainer path --- docs/government.md | 22 ++++++++++++++++++++++ lib/routes/v2ex/post.js | 3 +++ lib/v2/gov/gz/index.js | 38 ++++++++++++++++++++++++++++++++++++++ lib/v2/gov/maintainer.js | 2 ++ lib/v2/gov/radar.js | 11 +++++++++++ lib/v2/gov/router.js | 1 + 6 files changed, 77 insertions(+) create mode 100644 lib/v2/gov/gz/index.js diff --git a/docs/government.md b/docs/government.md index 6810a5d19d..931cc1d4c8 100644 --- a/docs/government.md +++ b/docs/government.md @@ -180,6 +180,28 @@ pageClass: routes +## 广州市人民政府 + +### 新闻 + + + +| 广州要闻 | 今日头条 | 通知公告 | +| ---- | ---- | ---- | +| gzyw | jrtt | tzgg | + + + +### 政务公开 + + + +| 文字解读 | +| ---- | +| zcjd | + + + ## 国家广播电视总局 ### 分类 diff --git a/lib/routes/v2ex/post.js b/lib/routes/v2ex/post.js index 842f841c6e..5b4d26c4d7 100644 --- a/lib/routes/v2ex/post.js +++ b/lib/routes/v2ex/post.js @@ -1,5 +1,6 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); module.exports = async (ctx) => { const postid = ctx.params.postid; @@ -29,8 +30,10 @@ module.exports = async (ctx) => { guid: post.attr('id'), link: `${pageUrl}#${post.attr('id')}`, author: post.find('.dark').first().text(), + pubDate: parseDate(post.find('.ago').attr('title')), }; }) .reverse(), + allowEmpty: true, }; }; diff --git a/lib/v2/gov/gz/index.js b/lib/v2/gov/gz/index.js new file mode 100644 index 0000000000..06e17bf690 --- /dev/null +++ b/lib/v2/gov/gz/index.js @@ -0,0 +1,38 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +const rootUrl = 'https://www.gz.gov.cn'; + +const urlMap = { + gzyw: 'gzyw', + jrtt: 'jrtt', + tzgg: 'tzgg', + zcjd: 'zcjd/zcjd', +}; + +module.exports = async (ctx) => { + const channel = ctx.params.channel; + const category = ctx.params.category; + const url = `${rootUrl}/${channel}/${urlMap[category]}/`; + const response = await got(url); + const $ = cheerio.load(response.data); + + const items = $('.news_list li') + .toArray() + .map((item) => { + item = $(item); + const href = item.find('a').attr('href'); + return { + title: item.find('a').attr('title'), + link: href, + pubDate: parseDate(item.find('span').text()), + }; + }); + + ctx.state.data = { + title: `广州市人民政府 - ${$('.main_title').text()}`, + link: url, + item: items, + }; +}; diff --git a/lib/v2/gov/maintainer.js b/lib/v2/gov/maintainer.js index 88d9f483fb..17365a08fa 100644 --- a/lib/v2/gov/maintainer.js +++ b/lib/v2/gov/maintainer.js @@ -46,6 +46,8 @@ module.exports = { '/beijing/kw/:channel': ['Fatpandac'], '/guangdong/tqyb/tfxtq': ['Fatpandac'], '/guangdong/tqyb/sncsyjxh': ['Fatpandac'], + '/gz/xw/:category': ['drgnchan'], + '/gz/zwgk/:category': ['drgnchan'], '/hebei/czt/xwdt/:category?': ['nczitzk'], '/huizhou/zwgk/:category?': ['Fatpandac'], '/hunan/changsha/major-email': ['shansing'], diff --git a/lib/v2/gov/radar.js b/lib/v2/gov/radar.js index 703aa18636..b34a226c12 100644 --- a/lib/v2/gov/radar.js +++ b/lib/v2/gov/radar.js @@ -428,6 +428,17 @@ module.exports = { }, ], }, + 'gz.gov.cn': { + _name: '广州市人民政府', + www: [ + { + title: '新闻', + docs: 'https://docs.rsshub.app/government.html#guang-zhou-shi-ren-min-zheng-fu', + source: ['/:channel/:category'], + target: (params) => `/gov/gz/${params.channel}/${params.category}`, + }, + ], + }, 'hebei.gov.cn': { _name: '河北省人民政府', czt: [ diff --git a/lib/v2/gov/router.js b/lib/v2/gov/router.js index 8e4d2784e5..71a7be5906 100644 --- a/lib/v2/gov/router.js +++ b/lib/v2/gov/router.js @@ -38,6 +38,7 @@ module.exports = function (router) { router.get('/beijing/kw/:channel', require('./beijing/kw/index')); router.get('/guangdong/tqyb/tfxtq', require('./guangdong/tqyb/tfxtq')); router.get('/guangdong/tqyb/sncsyjxh', require('./guangdong/tqyb/sncsyjxh')); + router.get('/gz/:channel/:category', require('./gz/index')); router.get('/hebei/czt/xwdt/:category?', require('./hebei/czt')); router.get('/huizhou/zwgk/:category?', require('./huizhou/zwgk/index')); router.get('/hunan/changsha/major-email', require('./hunan/changsha/major-email'));