From 44aa011ff4f297c5f9cd83774abb1eed6bdff3f0 Mon Sep 17 00:00:00 2001 From: Andvari <31068367+dzx-dzx@users.noreply.github.com> Date: Tue, 5 Sep 2023 23:43:20 +0800 Subject: [PATCH] fix(route): (Maybe) fix the stheadline feed occasionally dropping details. (#13206) --- lib/v2/stheadline/std/realtime.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/v2/stheadline/std/realtime.js b/lib/v2/stheadline/std/realtime.js index 8d79004bd37139..bfca3488a381a2 100644 --- a/lib/v2/stheadline/std/realtime.js +++ b/lib/v2/stheadline/std/realtime.js @@ -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(',')], + }; }) ) );