From 2e172d2451b242851c2377729a428c760c6fe7f8 Mon Sep 17 00:00:00 2001 From: nightmare-mio <52735303+nightmare-mio@users.noreply.github.com> Date: Thu, 23 Nov 2023 23:34:18 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E8=B1=86=E7=93=A3?= =?UTF-8?q?=E7=BD=91=E7=AB=99=E4=B8=AD=E5=85=B3=E4=BA=8E=E6=9F=90=E4=B9=A6?= =?UTF-8?q?=E7=9A=84=E8=AE=BA=E5=9D=9B=E9=A1=B5=E9=9D=A2(#13838)=20(#13850?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add (#13838) * 优化 * 添加文档 * delete no、删除评论的编号 * add index;添加了评论的编号 * add maintainer * add radar --- lib/v2/douban/maintainer.js | 1 + lib/v2/douban/other/discussion.js | 58 ++++++++++++++++++++++++++++ lib/v2/douban/radar.js | 8 ++++ lib/v2/douban/router.js | 1 + website/docs/routes/social-media.mdx | 4 ++ 5 files changed, 72 insertions(+) create mode 100644 lib/v2/douban/other/discussion.js diff --git a/lib/v2/douban/maintainer.js b/lib/v2/douban/maintainer.js index a3b89fa400a1dc..646e40b0136a8f 100644 --- a/lib/v2/douban/maintainer.js +++ b/lib/v2/douban/maintainer.js @@ -26,4 +26,5 @@ module.exports = { '/replied/:uid': ['nczitzk'], '/replies/:uid': ['nczitzk'], '/topic/:id/:sort?': ['LogicJake'], + '/:id/discussion': ['nightmare-mio'], }; diff --git a/lib/v2/douban/other/discussion.js b/lib/v2/douban/other/discussion.js new file mode 100644 index 00000000000000..8e4bf1ca623295 --- /dev/null +++ b/lib/v2/douban/other/discussion.js @@ -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 `