Neueste Artikel in Top Stories: isti izvajalec vsaj 5 mest narazen
This commit is contained in:
@@ -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 }> }) {
|
function MobileMosaic({ latest, popular, focalPoints }: { latest: Article[]; popular?: Article[]; focalPoints?: Record<string, { x: number; y: number }> }) {
|
||||||
const pageSize = 3;
|
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 totalPages = Math.max(1, Math.ceil(pool.length / pageSize));
|
||||||
|
|
||||||
const [page, setPage] = useState(0);
|
const [page, setPage] = useState(0);
|
||||||
@@ -940,7 +959,7 @@ export default function Home() {
|
|||||||
</div>
|
</div>
|
||||||
<div className="lg:col-span-1 space-y-4 lg:flex lg:flex-col">
|
<div className="lg:col-span-1 space-y-4 lg:flex lg:flex-col">
|
||||||
<SidebarWeatherWidget />
|
<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 />
|
<SidebarAd />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user