feat(route): 参考消息 (#9564)
* feat(route): 参考消息 * fixed the router's & ref bugs * docs: fix example * fix: prefer https * fix: radar Co-authored-by: alex <yuxin2@mgtv.com>
This commit is contained in:
parent
103a14ba06
commit
5f4cf8a2f0
|
|
@ -521,6 +521,16 @@ Category 列表:
|
|||
|
||||
<Route author="boypt" example="/caixin/yxnews" path="/caixin/yxnews"/>
|
||||
|
||||
## 参考消息
|
||||
|
||||
### 新闻分类
|
||||
|
||||
<Route author="yuxinliu-alex" example="/cankaoxiaoxi/news/military_news" path="/cankaoxiaoxi/news/:category">
|
||||
|
||||
| 中国 | 国际 | 军事 | 台海 | 财经 | 科技 | 文化 |
|
||||
| ---------- | ---------- | ------------- | ----------- | ------------ | --------------- | ------------ |
|
||||
| china_news | world_news | military_news | taiwan_news | finance_news | technology_news | culture_news |
|
||||
|
||||
## 朝日新聞中文網(繁體中文版)
|
||||
|
||||
::: tip 提示
|
||||
|
|
|
|||
|
|
@ -0,0 +1,81 @@
|
|||
const got = require('@/utils/got');
|
||||
const timezone = require('@/utils/timezone');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
const nodes = {
|
||||
china_news: {
|
||||
title: '中国',
|
||||
url: 'https://china.cankaoxiaoxi.com/',
|
||||
},
|
||||
world_news: {
|
||||
title: '国际',
|
||||
url: 'https://world.cankaoxiaoxi.com/',
|
||||
},
|
||||
military_news: {
|
||||
title: '军事',
|
||||
url: 'https://mil.cankaoxiaoxi.com/',
|
||||
},
|
||||
taiwan_news: {
|
||||
title: '台海',
|
||||
url: 'https://tw.cankaoxiaoxi.com/',
|
||||
},
|
||||
finance_news: {
|
||||
title: '财经',
|
||||
url: 'https://finance.cankaoxiaoxi.com/',
|
||||
},
|
||||
technology_news: {
|
||||
title: '科技',
|
||||
url: 'https://science.cankaoxiaoxi.com/',
|
||||
},
|
||||
culture_news: {
|
||||
title: '文化',
|
||||
url: 'https://culture.cankaoxiaoxi.com/',
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const category = ctx.params.category;
|
||||
|
||||
const currentUrl = nodes[category].url;
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const list = $('a', '.toutiao')
|
||||
.filter(function () {
|
||||
return $(this).text() !== '';
|
||||
})
|
||||
.map((_, item) => ({
|
||||
link: $(item).attr('href'),
|
||||
}))
|
||||
.get();
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
item.title = content('h1.articleHead').text();
|
||||
item.pubDate = timezone(parseDate(content('span#pubtime_baidu').text()), +8);
|
||||
item.author = content('span#source_baidu').text();
|
||||
item.description = content('div.articleText').html();
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${nodes[category].title} 参考消息`,
|
||||
link: currentUrl,
|
||||
description: '参考消息',
|
||||
language: 'zh-cn',
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
'/news/:category': ['yuxinliu-alex'],
|
||||
};
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
module.exports = {
|
||||
'cankaoxiaoxi.com': {
|
||||
_name: '参考消息',
|
||||
china: [
|
||||
{
|
||||
title: '中国新闻',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#can-kao-xiao-xi',
|
||||
source: ['/'],
|
||||
target: '/cankaoxiaoxi/news/china_news',
|
||||
},
|
||||
],
|
||||
culture: [
|
||||
{
|
||||
title: '文化新闻',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#can-kao-xiao-xi',
|
||||
source: ['/'],
|
||||
target: '/cankaoxiaoxi/news/culture_news',
|
||||
},
|
||||
],
|
||||
finance: [
|
||||
{
|
||||
title: '财经新闻',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#can-kao-xiao-xi',
|
||||
source: ['/'],
|
||||
target: '/cankaoxiaoxi/news/finance_news',
|
||||
},
|
||||
],
|
||||
mil: [
|
||||
{
|
||||
title: '军事新闻',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#can-kao-xiao-xi',
|
||||
source: ['/'],
|
||||
target: '/cankaoxiaoxi/news/military_news',
|
||||
},
|
||||
],
|
||||
science: [
|
||||
{
|
||||
title: '科技新闻',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#can-kao-xiao-xi',
|
||||
source: ['/'],
|
||||
target: '/cankaoxiaoxi/news/technology_news',
|
||||
},
|
||||
],
|
||||
tw: [
|
||||
{
|
||||
title: '台海新闻',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#can-kao-xiao-xi',
|
||||
source: ['/'],
|
||||
target: '/cankaoxiaoxi/news/taiwan_news',
|
||||
},
|
||||
],
|
||||
world: [
|
||||
{
|
||||
title: '国际新闻',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#can-kao-xiao-xi',
|
||||
source: ['/'],
|
||||
target: '/cankaoxiaoxi/news/world_news',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = function (router) {
|
||||
router.get('/news/:category', require('./index'));
|
||||
};
|
||||
Loading…
Reference in New Issue