-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* add (#13838) * 优化 * 添加文档 * delete no、删除评论的编号 * add index;添加了评论的编号 * add maintainer * add radar
- Loading branch information
1 parent
0a7537a
commit 2e172d2
Showing
5 changed files
with
72 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
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,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, | ||
}; | ||
}; |
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