fix(route): Bangumi 小组话题尝试获取全文 (#11384)

This commit is contained in:
Neko Aria 2022-12-05 23:52:30 +08:00 committed by GitHub
parent f796ff1d54
commit a257b9adc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 9 deletions

View File

@ -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 + '<br><br>' + 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,
};
};