From 45b3d978b112f50e451d5d495e2249cc1d8d1dc8 Mon Sep 17 00:00:00 2001 From: nczitzk Date: Tue, 27 Oct 2020 22:45:27 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=B1=86=E7=93=A3=E6=97=A5=E8=AE=B0?= =?UTF-8?q?=E6=9C=80=E6=96=B0=E5=9B=9E=E5=BA=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/douban/replies.js | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/lib/routes/douban/replies.js b/lib/routes/douban/replies.js index 6f1ba0b9e..8e9555110 100644 --- a/lib/routes/douban/replies.js +++ b/lib/routes/douban/replies.js @@ -34,25 +34,22 @@ module.exports = async (ctx) => { method: 'get', url: item.link, }); - const content = cheerio.load(detailResponse.data); - const commentsConfig = content('script').eq(16).html().replace('var _COMMENTS_CONFIG =', ''); - const comments = JSON.parse(commentsConfig.match(/'comments':(.*?)}],/)[1] + '}]'); - let title, description, pubDate; + const comments = JSON.parse(detailResponse.data.match(/'comments':(.*)}],/)[1] + '}]'); for (const c of comments) { if (c.id === item.link.split('#')[1]) { - (title = `${c.author.name} 于 ${c.create_time} 的回应`), (description = c.text); - pubDate = new Date(c.create_time + ' GMT+8').toUTCString(); - break; + return { + link: item.link, + title: `${c.author.name} 于 ${c.create_time} 的回应`, + pubDate: new Date(c.create_time + ' GMT+8').toUTCString(), + description: c.text, + author: c.author.name, + }; + } else if (c.replies.length > 0) { + comments.push(...c.replies); } } - - item.title = title; - item.description = description; - item.pubDate = pubDate; - - return item; }) ) );