diff --git a/server/routes.ts b/server/routes.ts index cd818f5..62dc120 100644 --- a/server/routes.ts +++ b/server/routes.ts @@ -1073,16 +1073,37 @@ export async function registerRoutes( signal: AbortSignal.timeout(10000), }); const arts: any[] = await r.json(); - const items = (Array.isArray(arts) ? arts : []) + const sveze = (Array.isArray(arts) ? arts : []) .filter((a) => a && a.slug && a.title) .sort((a, b) => String(b.publishedAt || "").localeCompare(String(a.publishedAt || ""))) - .slice(0, 12) - .map((a) => ({ - title: String(a.title), - link: `https://news.folx.tv/${a.slug}`, - source: String(a.category || "FOLX NEWS"), - pubDate: String(a.publishedAt || ""), - })); + .slice(0, 60); + + // Rubrike se morajo izmenjevati: sicer pridejo trije Sporti zapored, + // ker jih bot objavi v svezju. Vzamemo po eno iz vsake rubrike v krogu, + // znotraj rubrike pa ostane vrstni red po datumu. + const poRubriki = new Map(); + for (const a of sveze) { + const k = String(a.category || "FOLX NEWS"); + if (!poRubriki.has(k)) poRubriki.set(k, []); + poRubriki.get(k)!.push(a); + } + const kroznik: any[] = []; + let se = true; + while (se && kroznik.length < 12) { + se = false; + for (const vrsta of poRubriki.values()) { + const a = vrsta.shift(); + if (a) { kroznik.push(a); se = true; } + if (kroznik.length >= 12) break; + } + } + + const items = kroznik.map((a) => ({ + title: String(a.title), + link: `https://news.folx.tv/${a.slug}`, + source: String(a.category || "FOLX NEWS"), + pubDate: String(a.publishedAt || ""), + })); if (items.length > 0) setCache(cacheKey, items); res.json(items); } catch (err: any) {