Enhancement: Readhub-每日早报 (#1079)

- Closes #1078
This commit is contained in:
凉凉 2018-11-06 20:14:36 +08:00 committed by DIYgod
parent 73f1a2b8d2
commit bee92cf718
2 changed files with 16 additions and 8 deletions

View File

@ -2016,9 +2016,9 @@ IATA 国际航空运输协会机场代码, 参见[维基百科 国际航空运
<route name="分类" author="WhiteWorld" example="/readhub/category/topic" path="/readhub/category/:category" :paramsDesc="['分类名']">
| 热门话题 | 科技动态 | 开发者资讯 | 区块链快讯 |
| -------- | -------- | ---------- | ---------- |
| topic | news | technews | blockchain |
| 热门话题 | 科技动态 | 开发者资讯 | 区块链快讯 | 每日早报 |
| -------- | -------- | ---------- | ---------- | -------- |
| topic | news | technews | blockchain | daily |
</route>

View File

@ -4,6 +4,7 @@ module.exports = async (ctx) => {
const category = ctx.params.category;
let title;
let path = category;
switch (category) {
case 'topic':
title = '热门话题';
@ -17,13 +18,20 @@ module.exports = async (ctx) => {
case 'blockchain':
title = '区块链快讯';
break;
case 'daily':
title = '每日早报';
break;
default:
break;
}
if (path === 'daily') {
path = 'topic/daily';
}
const response = await axios({
method: 'get',
url: `https://api.readhub.cn/${category}`,
url: `https://api.readhub.cn/${path}`,
});
const data = response.data;
@ -33,10 +41,10 @@ module.exports = async (ctx) => {
link: 'https://readhub.cn',
item: data.data.map((item) => ({
title: item.title,
pubDate: new Date(item.publishDate).toUTCString(),
description: item.summary,
guid: item.id,
link: item.url || item.newsArray[0].url,
pubDate: new Date(item.publishDate || Date.now()).toUTCString(),
description: item.summary || item.title,
guid: `/${category}/${item.id}`,
link: category === 'daily' ? `https://readhub.cn/topic/${item.id}` : item.url || item.newsArray[0].url,
})),
};
};