From e761af6c863f599d283cb25956d761d97fcc124d Mon Sep 17 00:00:00 2001 From: Ethan Shen <42264778+nczitzk@users.noreply.github.com> Date: Wed, 3 Aug 2022 01:27:19 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E4=B8=AD=E5=9B=BD?= =?UTF-8?q?=E8=BD=BD=E4=BA=BA=E8=88=AA=E5=A4=A9=20(#10355)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): add 中国载人航天 * docs: add category for /fxrw * update lib/v2/gov/cmse/index.js Co-authored-by: Tony * docs: add xwzt --- docs/government.md | 76 +++++++++++++++++++++++ lib/v2/gov/cmse/fxrw.js | 40 ++++++++++++ lib/v2/gov/cmse/index.js | 67 ++++++++++++++++++++ lib/v2/gov/cmse/templates/description.art | 11 ++++ lib/v2/gov/maintainer.js | 10 +++ lib/v2/gov/radar.js | 65 +++++++++++++++++++ lib/v2/gov/router.js | 2 + 7 files changed, 271 insertions(+) create mode 100644 lib/v2/gov/cmse/fxrw.js create mode 100644 lib/v2/gov/cmse/index.js create mode 100644 lib/v2/gov/cmse/templates/description.art diff --git a/docs/government.md b/docs/government.md index 59325cd96..6818c615b 100644 --- a/docs/government.md +++ b/docs/government.md @@ -758,6 +758,82 @@ pageClass: routes +## 中国载人航天 + +### 综合新闻 + + + +### 研制进展 + + + +### 官方公告 + + + +### 飞行任务 + + + +### 任务动态 + + + +::: tip 提示 + +下表分类可能并不完整。请查看各飞行任务详情页获得完整分类。 + +::: + +| 任务动态 | 综合新闻 | 视频 | 图片新闻 | 媒体聚焦 | +| ---- | ---- | -- | ---- | ---- | +| rwdt | zhxw | sp | tpxw | mtjj | + + + +### 空间科学 + + + +| 空间科学研究与应用 | 航天技术试验 | 航天医学实验 | +| --------- | ------ | ------ | +| kjkxyjyyy | htjssy | htyxsy | + +### 国际合作 + + + +### 环球视野 + + + +| 最新动态 | 美国 | 俄罗斯 | 欧洲 | 日本 | 印度 | 领域动态 | +| ----- | -- | --- | -- | -- | -- | ---- | +| zxdta | mg | els | oz | rb | yd | lydt | + + + +### 专题报道 + + + +| 新闻发布会 | 学术大会 | 标准 | 新闻专题 | +| ----- | ---- | -- | ---- | +| xwfdh | xsdh | bz | xwzt | + + + +### 科普教育 + + + +| 科普活动 | 太空课堂 | 航天知识 | +| ---- | ---- | ---- | +| kphd | tkkt | ttzs | + + + ## 中国证券监督管理委员会 ### 发审委公告 diff --git a/lib/v2/gov/cmse/fxrw.js b/lib/v2/gov/cmse/fxrw.js new file mode 100644 index 000000000..c5c75ad8f --- /dev/null +++ b/lib/v2/gov/cmse/fxrw.js @@ -0,0 +1,40 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const timezone = require('@/utils/timezone'); +const { parseDate } = require('@/utils/parse-date'); +const { art } = require('@/utils/render'); +const path = require('path'); + +module.exports = async (ctx) => { + const rootUrl = 'http://www.cmse.gov.cn'; + const currentUrl = `${rootUrl}/fxrw/`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const items = $('#list li a') + .toArray() + .map((item) => { + item = $(item); + + return { + title: item.find('.title').text().split(':').pop().trim(), + link: new URL(item.attr('href'), currentUrl), + pubDate: timezone(parseDate(item.find('.infoR').first().text().trim(), 'YYYY年M月D日H时m分'), +8), + description: art(path.join(__dirname, 'templates/description.art'), { + image: item.find('img').attr('src'), + description: item.find('.info').html(), + }), + }; + }); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/gov/cmse/index.js b/lib/v2/gov/cmse/index.js new file mode 100644 index 000000000..8fd84858f --- /dev/null +++ b/lib/v2/gov/cmse/index.js @@ -0,0 +1,67 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const timezone = require('@/utils/timezone'); +const { parseDate } = require('@/utils/parse-date'); +const { art } = require('@/utils/render'); +const path = require('path'); + +module.exports = async (ctx) => { + ctx.path = ctx.path.replace(/(^\/cmse|\/$)/g, ''); + + const rootUrl = 'http://www.cmse.gov.cn'; + const currentUrl = `${rootUrl}${ctx.path === '' ? '/xwzx/zhxw/' : `${ctx.path}/`}`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + let items = $('#list li a') + .slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 15) + .toArray() + .map((item) => { + item = $(item); + + const pubDate = item.next().text(); + const link = new URL(item.attr('href'), currentUrl).href; + + return { + title: item.text(), + pubDate: parseDate(pubDate), + link: /\.html$/.test(link) ? link : `${link}#${pubDate}`, + }; + }); + + items = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + + const content = cheerio.load(detailResponse.data); + + content('.share').remove(); + + const detailPubTimeMatches = detailResponse.data.match(/__\$pubtime='(.*?)';var/); + + item.pubDate = detailPubTimeMatches ? timezone(parseDate(detailPubTimeMatches[1]), +8) : item.pubDate; + item.description = art(path.join(__dirname, 'templates/description.art'), { + video: content('#con_video').html(), + description: content('.TRS_Editor, #content').html(), + }); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/gov/cmse/templates/description.art b/lib/v2/gov/cmse/templates/description.art new file mode 100644 index 000000000..e1f6cd135 --- /dev/null +++ b/lib/v2/gov/cmse/templates/description.art @@ -0,0 +1,11 @@ +{{ if image }} + +
+{{ /if }} +{{ if video }} +{{@ video }} +
+{{ /if }} +{{ if description }} +{{@ description }} +{{ /if }} diff --git a/lib/v2/gov/maintainer.js b/lib/v2/gov/maintainer.js index 942cb3bbf..9513864e8 100644 --- a/lib/v2/gov/maintainer.js +++ b/lib/v2/gov/maintainer.js @@ -1,5 +1,15 @@ module.exports = { // ministry + '/cmse/xwzx/zhxw': ['nczitzk'], + '/cmse/xwzx/yzjz': ['nczitzk'], + '/cmse/gfgg': ['nczitzk'], + '/cmse/fxrw': ['nczitzk'], + '/cmse/kjkx/:id': ['nczitzk'], + '/cmse/gjhz': ['nczitzk'], + '/cmse/hqsy/:id': ['nczitzk'], + '/cmse/ztbd/:id': ['nczitzk'], + '/cmse/kpjy/:id': ['nczitzk'], + '/cmse/:path+': ['nczitzk'], '/customs/list/:gchannel?': ['Jeason0228', 'TonyRL'], '/fmprc/:category?': ['nicolaszf', 'nczitzk'], '/immiau/news': ['liu233w'], diff --git a/lib/v2/gov/radar.js b/lib/v2/gov/radar.js index 1a6e82631..05cb2af21 100644 --- a/lib/v2/gov/radar.js +++ b/lib/v2/gov/radar.js @@ -297,6 +297,71 @@ module.exports = { }, ], }, + 'cmse.gov.cn': { + _name: '中国载人航天', + www: [ + { + title: '综合新闻', + docs: 'https://docs.rsshub.app/government.html#zhong-guo-zai-ren-hang-tian', + source: ['/xwzx/zhxw'], + target: '/gov/cmse/xwzx/zhxw', + }, + { + title: '研制进展', + docs: 'https://docs.rsshub.app/government.html#zhong-guo-zai-ren-hang-tian', + source: ['/xwzx/yzjz'], + target: '/gov/cmse/xwzx/yzjz', + }, + { + title: '官方公告', + docs: 'https://docs.rsshub.app/government.html#zhong-guo-zai-ren-hang-tian', + source: ['/gfgg'], + target: '/gov/cmse/gfgg', + }, + { + title: '飞行任务', + docs: 'https://docs.rsshub.app/government.html#zhong-guo-zai-ren-hang-tian', + source: ['/fxrw'], + target: '/gov/cmse/fxrw', + }, + { + title: '任务动态', + docs: 'https://docs.rsshub.app/government.html#zhong-guo-zai-ren-hang-tian', + source: ['/fxrw/:id/:category'], + target: '/gov/cmse/fxrw/:id/:category', + }, + { + title: '空间科学', + docs: 'https://docs.rsshub.app/government.html#zhong-guo-zai-ren-hang-tian', + source: ['/kjkx/:id'], + target: '/gov/cmse/kjkx/:id', + }, + { + title: '国际合作', + docs: 'https://docs.rsshub.app/government.html#zhong-guo-zai-ren-hang-tian', + source: ['/gjhz'], + target: '/gov/cmse/gjhz', + }, + { + title: '环球视野', + docs: 'https://docs.rsshub.app/government.html#zhong-guo-zai-ren-hang-tian', + source: ['/hqsy/:id'], + target: '/gov/cmse/hqsy/:id', + }, + { + title: '专题报道', + docs: 'https://docs.rsshub.app/government.html#zhong-guo-zai-ren-hang-tian', + source: ['/ztbd/:id'], + target: '/gov/cmse/ztbd/:id', + }, + { + title: '科普教育', + docs: 'https://docs.rsshub.app/government.html#zhong-guo-zai-ren-hang-tian', + source: ['/kpjy/:id'], + target: '/gov/cmse/kpjy/:id', + }, + ], + }, 'customs.gov.cn': { _name: '中华人民共和国海关总署', www: [ diff --git a/lib/v2/gov/router.js b/lib/v2/gov/router.js index 81955c07a..de968b305 100644 --- a/lib/v2/gov/router.js +++ b/lib/v2/gov/router.js @@ -1,5 +1,7 @@ module.exports = function (router) { // ministry + router.get('/cmse/fxrw', require('./cmse/fxrw')); + router.get(/cmse(\/[\w/-]+)?/, require('./cmse')); router.get('/customs/list/:gchannel?', require('./customs/list')); router.get('/fmprc/:category?', require('./mfa/wjdt')); router.get('/immiau/news', require('./immiau/news'));