feat: 新增china.com RSS (#10532)

* 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 <jiaaoMario@gmail.com>
This commit is contained in:
mario.ma
2022-08-19 01:53:29 +08:00
committed by GitHub
parent 2bcddf44c3
commit d2eb1ac19c
7 changed files with 162 additions and 24 deletions

View File

@@ -131,6 +131,25 @@ Compared to the official one, the RSS feed generated by RSSHub not only has more
</RouteEn>
## China.com
### Military - Military News
<RouteEn author="jiaaoMario" example="/china/news/military" path="/china/news/military">
</RouteEn>
### News and current affairs
<RouteEn author="jiaaoMario" example="/china/news" path="/china/news/:category?" :paramsDesc="['Category of news. See the form below for details, default is china news.']">
Category of news
| China News | International News | Social News | Breaking News |
| -------- | ------------- | ------ | ------- |
| domestic | international | social | news100 |
</RouteEn>
## Common App
### Blog

View File

@@ -4226,6 +4226,25 @@ wechat-feeds 来源[已停止更新](https://github.com/hellodword/wechat-feeds/
<Route author="nczitzk" example="/cria/news/1" path="/cria/news/:id?" :paramsDesc="['列表 id可在列表页的 URL 中找到,默认为首页']"/>
## 中华网
### 军事 - 军事新闻
<Route author="jiaaoMario" example="/china/news/military" path="/china/news/military">
</Route>
### 时事新闻
<Route author="jiaaoMario" example="/china/news" path="/china/news/:category?" :paramsDesc="['新闻类型,见下表,默认为国内新闻']">
新闻类型
| 国内新闻 | 国际新闻 | 社会新闻 | 新闻热榜 |
| -------- | ------------- | ------ | ------- |
| domestic | international | social | news100 |
</Route>
## 重构
### 推荐

View File

@@ -0,0 +1,4 @@
module.exports = {
'/news/military': ['jiaaoMario'],
'/news/:category?': ['jiaaoMario'],
};

View File

@@ -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(),
};
};

View File

@@ -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(),
};
};

21
lib/v2/china/radar.js Normal file
View File

@@ -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?',
},
],
},
};

4
lib/v2/china/router.js Normal file
View File

@@ -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'));
};