Skip to content

Commit

Permalink
fix(route): (Maybe) fix the stheadline feed occasionally dropping det…
Browse files Browse the repository at this point in the history
…ails. (DIYgod#13206)
  • Loading branch information
dzx-dzx authored Sep 5, 2023
1 parent ababfbc commit 44aa011
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/v2/stheadline/std/realtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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(',')],
};
})
)
);
Expand Down

0 comments on commit 44aa011

Please sign in to comment.