Skip to content

Commit

Permalink
添加豆瓣小组 (DIYgod#306)
Browse files Browse the repository at this point in the history
* feat:添加豆瓣小组

* fix: add author & create time in douban topic

* fix: topic create time

* fix: add br

* fix: image error

* fix: add default image src

* feat: add douban group readme

* fix: fix get douban group image error

* fix: get douban image error

* feat: decrease topic count
  • Loading branch information
derycktse authored and DIYgod committed Jun 20, 2018
1 parent 685d7b4 commit 37d2d3c
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇
- 正在上映的高分电影
- 即将上映的电影
- 北美票房榜
- 小组
- 煎蛋
- 无聊图
- 喷嚏
Expand Down
9 changes: 9 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,15 @@ city: 城市的中文名,可选,默认北京

参数: 无

### 豆瓣小组

举例: [https://rsshub.app/douban/group/camera](https://rsshub.app/douban/group/camera)

路由: `/douban/group/:groupid`

参数:
groupid: 豆瓣小组的 id

## 煎蛋

### 无聊图
Expand Down
1 change: 1 addition & 0 deletions router.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ router.get('/douban/movie/playing/:score', require('./routes/douban/playing'));
router.get('/douban/movie/playing/:score/:city', require('./routes/douban/playing'));
router.get('/douban/movie/later', require('./routes/douban/later'));
router.get('/douban/movie/ustop', require('./routes/douban/ustop'));
router.get('/douban/group/:groupid', require('./routes/douban/group'));

// 煎蛋
router.get('/jandan/pic', require('./routes/jandan/pic'));
Expand Down
52 changes: 52 additions & 0 deletions routes/douban/group.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const axios = require('axios');

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

const response = await axios({
method: 'get',
url: `https://api.douban.com/v2/group/${groupid}/topics?start=0&count=10`,
});

const topics = response.data.topics;

// 替换图片到内容中
topics.map((topic) => {
const { photos = [] } = topic;
let { content } = topic;

content = content.replace(/ /g, '<br>');
topic.content = content.replace(/<(\d*)>/g, function() {
try {
const photo = photos.filter((p) => p.seq_id === arguments[1]);

if (photo.length > 0) {
const src = photo[0].alt;
return `<img referrerpolicy="no-referrer" src='${src}'/><br>`;
} else {
return '';
}
} catch (ex) {
console.log(arguments);
console.log(photos);
console.log(ex);
return '';
}
});
return topic;
});

ctx.state.data = {
title: `豆瓣小组-${groupid}`,
link: `https://www.douban.com/group/${groupid}/`,
item: topics.map((topic) => ({
title: `${topic.title} from ${topic.author.name}`,
description: `<a href="${topic.author.alt}"><img src='${topic.author.avatar}'/></a><br>
作者:<a href="${topic.author.alt}">${topic.author.name}</a><br>
发表时间: ${topic.created}<br>
最后更新: ${topic.updated}<br><br>
${topic.content}`,
link: topic.share_url,
})),
};
};

0 comments on commit 37d2d3c

Please sign in to comment.