fix(route): Bangumi 小组话题尝试获取全文 (#11384)
This commit is contained in:
parent
f796ff1d54
commit
a257b9adc7
|
|
@ -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,
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue