rss: add readhub (#204)
* rss: add readhub * rss: adjust readhub router
This commit is contained in:
@@ -117,6 +117,8 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇
|
||||
* 最热/最新主题
|
||||
* Telegram
|
||||
* 频道
|
||||
* Readhub
|
||||
* 分类
|
||||
|
||||
## 鸣谢
|
||||
|
||||
|
||||
@@ -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 |
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
})),
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user