forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
4 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,6 +78,7 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇 | |
- 正在上映的高分电影 | ||
- 即将上映的电影 | ||
- 北美票房榜 | ||
- 小组 | ||
- 煎蛋 | ||
- 无聊图 | ||
- 喷嚏 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
})), | ||
}; | ||
}; |