From a257b9adc7ff87ad119075bb3a9db42e8ea0eb62 Mon Sep 17 00:00:00 2001 From: Neko Aria <990879119@qq.com> Date: Mon, 5 Dec 2022 23:52:30 +0800 Subject: [PATCH] =?UTF-8?q?fix(route):=20Bangumi=20=E5=B0=8F=E7=BB=84?= =?UTF-8?q?=E8=AF=9D=E9=A2=98=E5=B0=9D=E8=AF=95=E8=8E=B7=E5=8F=96=E5=85=A8?= =?UTF-8?q?=E6=96=87=20(#11384)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/v2/bangumi/tv/group/topic.js | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/lib/v2/bangumi/tv/group/topic.js b/lib/v2/bangumi/tv/group/topic.js index 9142d967e..f99093989 100644 --- a/lib/v2/bangumi/tv/group/topic.js +++ b/lib/v2/bangumi/tv/group/topic.js @@ -10,17 +10,28 @@ module.exports = async (ctx) => { const $ = cheerio.load(html); const title = 'Bangumi - ' + $('.SecondaryNavTitle').text(); + const items = await Promise.all($('.topic_list .topic') + .toArray() + .map(async (elem) => { + const link = new URL($('.subject a', elem).attr('href'), base_url).href; + const fullText = await ctx.cache.tryGet(link, async () => { + const { data: html } = await got(link); + const $ = cheerio.load(html); + return $('.postTopic .topic_content').html(); + }); + const summary = 'Reply: ' + $('.posts', elem).text(); + return { + link, + title: $('.subject a', elem).attr('title'), + pubDate: parseDate($('.lastpost .time', elem).text()), + description: fullText ? summary + '

' + fullText : summary, + author: $('.author a', elem).text(), + }; + })); + ctx.state.data = { title, link, - item: $('.topic_list .topic') - .toArray() - .map((elem) => ({ - link: new URL($('.subject a', elem).attr('href'), base_url).href, - title: $('.subject a', elem).attr('title'), - pubDate: parseDate($('.lastpost .time', elem).text()), - description: 'Reply: ' + $('.posts', elem).text(), - author: $('.author a', elem).text(), - })), + item: items, }; };