Neueste Artikel in Top Stories: isti izvajalec vsaj 5 mest narazen

This commit is contained in:
FOLX Claude
2026-08-29 19:43:47 +02:00
parent 9c0e088f08
commit aacf46d523
+21 -2
View File
@@ -183,9 +183,28 @@ function MosaicHeading({ children }: { children: React.ReactNode }) {
);
}
/** Isti izvajalec ne sme stati drug ob drugem: med dvema clankoma vsaj 5 mest. */
function razmakniPoIzvajalcu(list: Article[], razmik = 5): Article[] {
const rest = [...(list || [])];
const out: Article[] = [];
const recent: string[] = [];
while (rest.length) {
let idx = rest.findIndex((a) => {
const k = artistKey(a?.title || "");
return !k || !recent.includes(k);
});
if (idx < 0) idx = 0;
const a = rest.splice(idx, 1)[0];
out.push(a);
recent.push(artistKey(a?.title || ""));
if (recent.length >= razmik) recent.shift();
}
return out;
}
function MobileMosaic({ latest, popular, focalPoints }: { latest: Article[]; popular?: Article[]; focalPoints?: Record<string, { x: number; y: number }> }) {
const pageSize = 3;
const pool = (latest || []).slice(0, 9);
const pool = razmakniPoIzvajalcu(latest || []).slice(0, 9);
const totalPages = Math.max(1, Math.ceil(pool.length / pageSize));
const [page, setPage] = useState(0);
@@ -940,7 +959,7 @@ export default function Home() {
</div>
<div className="lg:col-span-1 space-y-4 lg:flex lg:flex-col">
<SidebarWeatherWidget />
{articles && articles.length > 0 && <TopStoriesList articles={[...articles].sort((a, b) => new Date(b.publishedAt).getTime() - new Date(a.publishedAt).getTime()).slice(0, 8)} className="lg:flex-1 lg:min-h-0 overflow-hidden" />}
{articles && articles.length > 0 && <TopStoriesList articles={razmakniPoIzvajalcu([...articles].sort((a, b) => new Date(b.publishedAt).getTime() - new Date(a.publishedAt).getTime())).slice(0, 8)} className="lg:flex-1 lg:min-h-0 overflow-hidden" />}
<SidebarAd />
</div>
</div>