fix(route): (Maybe) fix the stheadline feed occasionally dropping details. (#13206)

This commit is contained in:
Andvari
2023-09-05 23:43:20 +08:00
committed by GitHub
parent ababfbc7ff
commit 44aa011ff4
+8 -7
View File
@@ -11,7 +11,7 @@ module.exports = async (ctx) => {
const { data: response } = await got(url);
const $ = cheerio.load(response);
const items = $(`${category === '即時' ? '.moreNews > .col-md-4' : ''} .media-body > .my-2 > a`)
let items = $(`${category === '即時' ? '.moreNews > .col-md-4' : ''} .media-body > .my-2 > a`)
.toArray()
.map((item) => {
item = $(item);
@@ -22,17 +22,18 @@ module.exports = async (ctx) => {
};
});
await Promise.all(
items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const { data: response } = await got(item.link);
const $ = cheerio.load(response);
item.description = $('.paragraphs').html();
item.pubDate = timezone(parseDate($('.content .date').text()), +8);
item.category = [$('nav .nav-item.active a')?.text()?.trim(), ...$("meta[name='keyword']").attr('content').split(',')];
return item;
return {
...item,
description: $('.paragraphs').html(),
pubDate: timezone(parseDate($('.content .date').text()), +8),
category: [$('nav .nav-item.active a')?.text()?.trim(), ...$("meta[name='keyword']").attr('content').split(',')],
};
})
)
);