Skip to content

Commit

Permalink
rss: add readhub (DIYgod#204)
Browse files Browse the repository at this point in the history
* rss: add readhub

* rss: adjust readhub router
  • Loading branch information
WhiteWorld authored and DIYgod committed May 25, 2018
1 parent 14e7f91 commit 8fbde6f
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇
* 最热/最新主题
* Telegram
* 频道
* Readhub
* 分类

## 鸣谢

Expand Down
14 changes: 14 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 3 additions & 0 deletions router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 46 additions & 0 deletions routes/readhub/category.js
Original file line number Diff line number Diff line change
@@ -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,
})),
};
};

0 comments on commit 8fbde6f

Please sign in to comment.