rss: add readhub (#204)

* rss: add readhub

* rss: adjust readhub router
This commit is contained in:
Liu
2018-05-25 21:54:06 +08:00
committed by DIYgod
parent 14e7f91aad
commit 8fbde6f7ba
4 changed files with 65 additions and 0 deletions
+2
View File
@@ -117,6 +117,8 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇
* 最热/最新主题
* Telegram
* 频道
* Readhub
* 分类
## 鸣谢
+14
View File
@@ -906,3 +906,17 @@ key: 产品密钥
路由: `/telegram/channel/:username`
参数: username,频道 username
## Readhub
### 分类
举例: [https://rsshub.app/readhub/category/topic](https://rsshub.app/readhub/category/topic)
路由: `/readhub/category/:category`
参数: category,分类名
| 热门话题 | 科技动态 | 开发者资讯 | 区块链快讯 |
| -------- | -------- | ---------- | ---------- |
| topic | news | technews | blockchain |
+3
View File
@@ -233,4 +233,7 @@ if (config.telegram && config.telegram.token) {
logger.warn('Telegram RSS is disabled for lacking config.');
}
// readhub
router.get('/readhub/category/:category', require('./routes/readhub/category'));
module.exports = router;
+46
View File
@@ -0,0 +1,46 @@
const axios = require('../../utils/axios');
const config = require('../../config');
module.exports = async (ctx) => {
const category = ctx.params.category;
let title;
switch (category) {
case 'topic':
title = '热门话题';
break;
case 'news':
title = '科技动态';
break;
case 'technews':
title = '开发者资讯';
break;
case 'blockchain':
title = '区块链快讯';
break;
default:
break;
}
const response = await axios({
method: 'get',
url: `https://api.readhub.me/${category}`,
headers: {
'User-Agent': config.ua,
},
});
const data = response.data;
ctx.state.data = {
title: `Readhub-${title}`,
link: 'https://readhub.me',
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,
})),
};
};