From d2eb1ac19cb7ce687612d57d3820162871e9c8bd Mon Sep 17 00:00:00 2001 From: "mario.ma" Date: Fri, 19 Aug 2022 01:53:29 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9Echina.com=20RSS=20(#1?= =?UTF-8?q?0532)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: add news router * feat: add news path * feat: change website category * feat: complate zhonghuawang * style: format code * docs: add english router doc * feat: 调整文件名称 * feat: 添加时间处理 * feat: cr commit Co-authored-by: majiaao --- docs/en/new-media.md | 19 ++++++++ docs/new-media.md | 67 ++++++++++++++++++---------- lib/v2/china/maintainer.js | 4 ++ lib/v2/china/news/highlights/news.js | 40 +++++++++++++++++ lib/v2/china/news/military/news.js | 31 +++++++++++++ lib/v2/china/radar.js | 21 +++++++++ lib/v2/china/router.js | 4 ++ 7 files changed, 162 insertions(+), 24 deletions(-) create mode 100644 lib/v2/china/maintainer.js create mode 100644 lib/v2/china/news/highlights/news.js create mode 100644 lib/v2/china/news/military/news.js create mode 100644 lib/v2/china/radar.js create mode 100644 lib/v2/china/router.js diff --git a/docs/en/new-media.md b/docs/en/new-media.md index 4ca86e70ef..79e1cb5774 100644 --- a/docs/en/new-media.md +++ b/docs/en/new-media.md @@ -131,6 +131,25 @@ Compared to the official one, the RSS feed generated by RSSHub not only has more +## China.com + +### Military - Military News + + + + +### News and current affairs + + + +Category of news + +| China News | International News | Social News | Breaking News | +| -------- | ------------- | ------ | ------- | +| domestic | international | social | news100 | + + + ## Common App ### Blog diff --git a/docs/new-media.md b/docs/new-media.md index b435e637a7..c81794c7a3 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -2615,51 +2615,51 @@ column 为 third 时可选的 category: - 人工智能 - | 学术 | 开发者 | - | -------- | -------- | - | academic | yanxishe | + | 学术 | 开发者 | + | -------- | -------- | + | academic | yanxishe | - 数智化 - | 零售数智化 | 金融数智化 | 工业数智化 | 医疗数智化 | 城市数智化 | - | --------- | ---------- | ---------- | --------- | ----------- | - | redigital | findigital | mandigital | medigital | citydigital | + | 零售数智化 | 金融数智化 | 工业数智化 | 医疗数智化 | 城市数智化 | + | --------- | ---------- | ---------- | --------- | ----------- | + | redigital | findigital | mandigital | medigital | citydigital | - 金融科技 - | 科技巨头 | 银行 AI | 金融云 | 风控与安全 | - | ------- | ----- | ------------ | ------------ | - | BigTech | bank | FinanceCloud | DataSecurity | + | 科技巨头 | 银行 AI | 金融云 | 风控与安全 | + | ------- | ----- | ------------ | ------------ | + | BigTech | bank | FinanceCloud | DataSecurity | - 医疗科技 - | 医疗 AI | 投融资 | 医疗器械 | 互联网医疗 | 生物医药 | 健康险 | - | -------- | ----- | ----- | ---------------- | ------------ | ------------ | - | healthai | touzi | qixie | hulianwangyiliao | shengwuyiyao | jiankangxian | + | 医疗 AI | 投融资 | 医疗器械 | 互联网医疗 | 生物医药 | 健康险 | + | -------- | ----- | ----- | ---------------- | ------------ | ------------ | + | healthai | touzi | qixie | hulianwangyiliao | shengwuyiyao | jiankangxian | - 芯片 - | 材料设备 | 芯片设计 | 晶圆代工 | 封装测试 | - | --------- | ---------- | ------------- | --------- | - | materials | chipdesign | manufacturing | packaging | + | 材料设备 | 芯片设计 | 晶圆代工 | 封装测试 | + | --------- | ---------- | ------------- | --------- | + | materials | chipdesign | manufacturing | packaging | - 智慧城市 - | 智慧安防 | 智慧教育 | 智慧交通 | 智慧社区 | 智慧零售 | 智慧政务 | 智慧地产 | - | ------------- | -------------- | ------------------- | -------------- | -------------- | --------------- | -------- | - | smartsecurity | smarteducation | smarttransportation | smartcommunity | smartretailing | smartgovernment | proptech | + | 智慧安防 | 智慧教育 | 智慧交通 | 智慧社区 | 智慧零售 | 智慧政务 | 智慧地产 | + | ------------- | -------------- | ------------------- | -------------- | -------------- | --------------- | -------- | + | smartsecurity | smarteducation | smarttransportation | smartcommunity | smartretailing | smartgovernment | proptech | - 工业互联网 - | 工业软件 | 工业安全 | 5G 工业互联网 | 工业转型实践 | - | ---------- | -------- | -------- | --------- | - | gysoftware | gysafety | 5ggy | gypratice | + | 工业软件 | 工业安全 | 5G 工业互联网 | 工业转型实践 | + | ---------- | -------- | -------- | --------- | + | gysoftware | gysafety | 5ggy | gypratice | - AIoT - | 物联网 | 智能硬件 | 机器人 | 智能家居 | - | --- | ---- | ----- | --------- | - | 5G | arvr | robot | smarthome | + | 物联网 | 智能硬件 | 机器人 | 智能家居 | + | --- | ---- | ----- | --------- | + | 5G | arvr | robot | smarthome | @@ -4226,6 +4226,25 @@ wechat-feeds 来源[已停止更新](https://github.com/hellodword/wechat-feeds/ +## 中华网 + +### 军事 - 军事新闻 + + + + +### 时事新闻 + + + +新闻类型 + +| 国内新闻 | 国际新闻 | 社会新闻 | 新闻热榜 | +| -------- | ------------- | ------ | ------- | +| domestic | international | social | news100 | + + + ## 重构 ### 推荐 diff --git a/lib/v2/china/maintainer.js b/lib/v2/china/maintainer.js new file mode 100644 index 0000000000..3a51c3f620 --- /dev/null +++ b/lib/v2/china/maintainer.js @@ -0,0 +1,4 @@ +module.exports = { + '/news/military': ['jiaaoMario'], + '/news/:category?': ['jiaaoMario'], +}; diff --git a/lib/v2/china/news/highlights/news.js b/lib/v2/china/news/highlights/news.js new file mode 100644 index 0000000000..9ef6f95a52 --- /dev/null +++ b/lib/v2/china/news/highlights/news.js @@ -0,0 +1,40 @@ +const cheerio = require('cheerio'); +const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); + +const CATEGORY_MAP = { + domestic: 'domestic', + international: 'international', + social: 'social', + news100: 'news100', +}; + +module.exports = async (ctx) => { + const baseUrl = 'https://news.china.com'; + const category = CATEGORY_MAP[ctx.params.category] ?? CATEGORY_MAP.domestic; + const websiteUrl = `${baseUrl}/${category}`; + const response = await got(websiteUrl); + const data = response.data; + const $ = cheerio.load(data); + const categoryTitle = $('.wp_title').text(); + const news = $('.item_list li'); + ctx.state.data = { + title: `中华网-${categoryTitle}新闻`, + link: websiteUrl, + item: + news && + news + .map((_, item) => { + item = $(item); + return { + title: item.find('.item_title a').text(), + author: item.find('.item_source').text(), + category: `${categoryTitle}新闻`, + pubDate: parseDate(item.find('.item_time').text()), + description: item.find('.item_title a').text(), + link: item.find('li a').attr('href'), + }; + }) + .get(), + }; +}; diff --git a/lib/v2/china/news/military/news.js b/lib/v2/china/news/military/news.js new file mode 100644 index 0000000000..62f4d893aa --- /dev/null +++ b/lib/v2/china/news/military/news.js @@ -0,0 +1,31 @@ +const cheerio = require('cheerio'); +const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const websiteUrl = 'https://military.china.com/news/'; + const response = await got(websiteUrl); + const data = response.data; + const $ = cheerio.load(data); + const commonList = $('.listItem'); + + ctx.state.data = { + title: '中华网-军事新闻', + link: 'https://military.china.com/news/', + item: + commonList && + commonList + .map((_, item) => { + item = $(item); + return { + title: item.find('.tit a').text(), + author: '中华网军事', + category: '中华网军事', + pubDate: parseDate(item.find('.time').text()), + description: item.find('.tag').text(), + link: item.find('.tit a').attr('href'), + }; + }) + .get(), + }; +}; diff --git a/lib/v2/china/radar.js b/lib/v2/china/radar.js new file mode 100644 index 0000000000..3e4fba650a --- /dev/null +++ b/lib/v2/china/radar.js @@ -0,0 +1,21 @@ +module.exports = { + 'china.com': { + _name: '中华网', + military: [ + { + title: '军事新闻', + docs: 'https://docs.rsshub.app/new-media.html#zhong-hua-wang', + source: '/news', + target: '/china/news/military', + }, + ], + news: [ + { + title: '时事新闻', + docs: 'https://docs.rsshub.app/new-media.html#zhong-hua-wang', + source: '/:category', + target: '/china/news/:category?', + }, + ], + }, +}; diff --git a/lib/v2/china/router.js b/lib/v2/china/router.js new file mode 100644 index 0000000000..3008787af6 --- /dev/null +++ b/lib/v2/china/router.js @@ -0,0 +1,4 @@ +module.exports = (router) => { + router.get('/news/military', require('./news/military/news.js')); + router.get('/news/:category?', require('./news/highlights/news.js')); +};