From 5cf5d7660156532ed51acf96ec94008937319947 Mon Sep 17 00:00:00 2001 From: caty21 Date: Sat, 27 Jun 2026 16:20:09 +0200 Subject: [PATCH] fix: sort news by recency first, priority items get +3h boost (not fully separated) Co-Authored-By: Claude Sonnet 4.6 --- lib/newsfeed.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/newsfeed.ts b/lib/newsfeed.ts index 2f58184..d446459 100644 --- a/lib/newsfeed.ts +++ b/lib/newsfeed.ts @@ -847,12 +847,12 @@ export async function fetchAllNews(): Promise { const PRIORITY_SET = new Set(["Discours BC", "Décision Taux", "Crise", "Guerre", "Chef d'État", "Probabilités Taux"]); const isPrio = (item: NewsItem) => item.categories.some(c => PRIORITY_SET.has(c)); + const PRIO_BONUS_MS = 3 * 60 * 60 * 1000; // +3h boost pour les prioritaires deduped.sort((a, b) => { - const pa = isPrio(a) ? 1 : 0; - const pb = isPrio(b) ? 1 : 0; - if (pb !== pa) return pb - pa; - return b.publishedAt.localeCompare(a.publishedAt); + const ta = new Date(a.publishedAt).getTime() + (isPrio(a) ? PRIO_BONUS_MS : 0); + const tb = new Date(b.publishedAt).getTime() + (isPrio(b) ? PRIO_BONUS_MS : 0); + return tb - ta; }); return deduped;