Skip to content

Commit

Permalink
add disqus posts
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed May 9, 2018
1 parent 14d3f1e commit 8f633b3
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇
- 开发者头条
- 今天头条
- 独家号
- Disqus
- 评论

## 参与我们

Expand Down
3 changes: 3 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ module.exports = {
client_secret: 'lsACyCD94FhDUtGTXi3QzcFE2uU1hqtDaKeqrdwj',
username: 'rsshub@tmpmail.org',
password: 'rsshubpixiv'
},
disqus: {
api_key: 'E8Uh5l5fHZ6gD8U3KycjAIAk46f68Zw7C6eW8WSjZvCLXebZ7p0r1yrYDrLilk2F',
}
};
10 changes: 10 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -524,3 +524,13 @@ key: 产品密钥
路由: `/toutiao/user/:id`

参数: id,独家号 id,可在对应独家号页 URL 中找到

## Disqus

### 评论

举例: [https://rss.now.sh/disqus/posts/diygod-me](https://rss.now.sh/disqus/posts/diygod-me)

路由: `/disqus/posts/:forum`

参数: forum,网站的 disqus name
3 changes: 3 additions & 0 deletions router.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,7 @@ router.get('/biquge/novel/latestchapter/:id', require('./routes/biquge/chapter')
router.get('/toutiao/today', require('./routes/toutiao/today'));
router.get('/toutiao/user/:id', require('./routes/toutiao/user'));

// Disqus
router.get('/disqus/posts/:forum', require('./routes/disqus/posts'));

module.exports = router;
52 changes: 52 additions & 0 deletions routes/disqus/posts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const axios = require('axios');
const template = require('../../utils/template');
const config = require('../../config');

module.exports = async (ctx) => {
const forum = ctx.params.forum;

const response = await axios({
method: 'get',
url: `https://disqus.com/api/3.0/forums/listPosts.json?api_key=${config.disqus.api_key}&forum=${forum}`,
headers: {
'User-Agent': config.ua,
'Referer': 'https://disqus.com/'
}
});

const data = response.data.response;

const threadsObj = {};
data.forEach((item) => {
threadsObj[item.thread] = 1;
});
let threadsQuery = '';
Object.keys(threadsObj).forEach((item) => {
threadsQuery += `&thread=${item}`;
});

const responseThreads = await axios({
method: 'get',
url: `https://disqus.com/api/3.0/forums/listThreads.json?api_key=${config.disqus.api_key}&forum=${forum}${threadsQuery}`,
headers: {
'User-Agent': config.ua,
'Referer': 'https://disqus.com/'
}
});

const threads = responseThreads.data.response;

ctx.body = template({
title: `${forum} 的评论`,
description: `${forum} 的 disqus 评论`,
item: data.map((item) => {
const thread = threads.filter((i) => i.id === item.thread)[0];
return {
title: `${item.author.name}: ${item.raw_message > 24 ? item.raw_message.slice(0, 24) + '...' : item.raw_message}`,
description: `${item.author.name} 在《${thread.clean_title}》中发表评论: ${item.message}`,
pubDate: new Date(item.createdAt).toUTCString(),
link: `${thread.link}/#comment-${item.id}`
};
}),
});
};
2 changes: 1 addition & 1 deletion views/rss.art
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<rss version="2.0">
<channel>
<title><![CDATA[{{ title || 'RSSHub' }}]]></title>
<link>{{ link }}</link>
<link>{{ link || 'https://github.com/DIYgod/RSSHub' }}</link>
<description><![CDATA[{{ description || title }} - 使用 RSSHub(https://github.com/DIYgod/RSSHub) 构建]]></description>
<generator>RSSHub</generator>
<webMaster>i@html.love</webMaster>
Expand Down

0 comments on commit 8f633b3

Please sign in to comment.