Skip to content

Commit

Permalink
feat(route): add 豆瓣网站中关于某书的论坛页面(#13838) (#13850)
Browse files Browse the repository at this point in the history
* add (#13838)

* 优化

* 添加文档

* delete no、删除评论的编号

* add index;添加了评论的编号

* add maintainer

* add radar
  • Loading branch information
nightmare-mio authored Nov 23, 2023
1 parent 0a7537a commit 2e172d2
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/v2/douban/maintainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ module.exports = {
'/replied/:uid': ['nczitzk'],
'/replies/:uid': ['nczitzk'],
'/topic/:id/:sort?': ['LogicJake'],
'/:id/discussion': ['nightmare-mio'],
};
58 changes: 58 additions & 0 deletions lib/v2/douban/other/discussion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* @Author: nightmare-mio wanglongwei2009@qq.com
* @Date: 2023-11-20 23:36:12
* @LastEditTime: 2023-11-22 20:11:24
* @Description:
*/
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');

module.exports = async (ctx) => {
const { id } = ctx.params;
const link = 'https://book.douban.com/subject';
const { data: response } = await got(`${link}/${id}/discussion/`);
const $ = cheerio.load(response);
// 列表
const list = $('#posts-table>tbody>tr')
.toArray()
.slice(1)
.map((item) => {
item = $(item);
const a = item.find('a').first();
return {
title: a.attr('title'),
link: a.attr('href'),
pubDate: parseDate(item.find('.time').text()),
author: item.find('a').eq(1).text(),
};
});
const title = $('#content>h1').text();

const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const { data: response } = await got(item.link);
const $ = cheerio.load(response);
// 评论
const list = $('#comments>.comment-item').toArray();
const replyContent = list
.map((item, index) => {
const post = $(item);
const content = post.find('.content>p').html();
const author = post.find('.author>a').text();
return `<p><div>#${index + 1}: <i>${author}</i></div><div>${content}</div></p>`;
})
.join('');
item.description = `${$('#link-report>div').eq(1).html()}<div>${replyContent}</div>`;
return item;
})
)
);

ctx.state.data = {
title,
link: `${link}/${id}/discussion`,
item: items,
};
};
8 changes: 8 additions & 0 deletions lib/v2/douban/radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,13 @@ module.exports = {
target: '/jobs/intern',
},
],
book: [
{
title: '读书论坛',
docs: 'https://docs.rsshub.app/routes/social-media#dou-ban',
source: '/:id/discussion',
target: '/:id/discussion',
},
],
},
};
1 change: 1 addition & 0 deletions lib/v2/douban/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ module.exports = function (router) {
router.get('/replied/:uid', require('./other/replied'));
router.get('/replies/:uid', require('./other/replies'));
router.get('/topic/:id/:sort?', require('./other/topic.js'));
router.get('/:id/discussion', require('./other/discussion.js'));
};
4 changes: 4 additions & 0 deletions website/docs/routes/social-media.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1457,6 +1457,10 @@ Country Code

</Route>

### 豆瓣读书论坛 {#dou-ban-du-shu-lun-tan}

<Route author="nightmare-mio" example="/douban/36328704/discussion" path="/douban/:id/discussion" paramsDesc={['书本id;默认论坛文章使用"按回应时间排序",仅第一页文章']}/>

## 饭否 {#fan-fou}

:::warning
Expand Down

0 comments on commit 2e172d2

Please sign in to comment.