naslovnica: isti izvajalec vsaj 5 mest narazen namesto premikanja clankov v drugo rubriko
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { artistKey } from "@/lib/artists";
|
||||
import { Link } from "wouter";
|
||||
import { type Article } from "@shared/schema";
|
||||
import { format } from "date-fns";
|
||||
@@ -772,6 +773,27 @@ export default function Home() {
|
||||
return [...head, ...tail];
|
||||
}, [articles]);
|
||||
|
||||
// Na naslovnici isti izvajalec ne sme stati drug ob drugem: med dvema clankoma
|
||||
// istega izvajalca mora biti vsaj 5 mest. Clanek ostane v rubriki News in v indeksu.
|
||||
const RAZMIK = 5;
|
||||
const spaced = useMemo(() => {
|
||||
const rest = [...shuffled];
|
||||
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;
|
||||
}, [shuffled]);
|
||||
|
||||
const widgets = useMemo(() => [
|
||||
{ id: "horoscope", el: <HoroscopeWidget key="horoscope" /> },
|
||||
{ id: "news", el: <div key="news" className="flex flex-col gap-4"><NewsWidget /></div> },
|
||||
@@ -794,19 +816,19 @@ export default function Home() {
|
||||
for (let r = 0; r < widgetRows; r++) {
|
||||
if (wi < widgets.length) items.push({ type: "widget", key: `w-${widgets[wi].id}`, widget: widgets[wi++] });
|
||||
if (wi < widgets.length) items.push({ type: "widget", key: `w-${widgets[wi].id}`, widget: widgets[wi++] });
|
||||
if (ai < shuffled.length) items.push({ type: "article", key: `a-${shuffled[ai].id}`, article: shuffled[ai++] });
|
||||
if (ai < shuffled.length) items.push({ type: "article", key: `a-${shuffled[ai].id}`, article: shuffled[ai++] });
|
||||
if (ai < spaced.length) items.push({ type: "article", key: `a-${spaced[ai].id}`, article: spaced[ai++] });
|
||||
if (ai < spaced.length) items.push({ type: "article", key: `a-${spaced[ai].id}`, article: spaced[ai++] });
|
||||
}
|
||||
|
||||
while (ai < shuffled.length) {
|
||||
items.push({ type: "article", key: `a-${shuffled[ai].id}`, article: shuffled[ai++] });
|
||||
while (ai < spaced.length) {
|
||||
items.push({ type: "article", key: `a-${spaced[ai].id}`, article: spaced[ai++] });
|
||||
}
|
||||
|
||||
const remainder = items.length % 4;
|
||||
if (remainder > 0 && shuffled.length > 0) {
|
||||
if (remainder > 0 && spaced.length > 0) {
|
||||
let fill = 0;
|
||||
while (items.length % 4 !== 0) {
|
||||
const art = shuffled[fill % shuffled.length];
|
||||
const art = spaced[fill % spaced.length];
|
||||
items.push({ type: "article", key: `fill-${fill}`, article: art });
|
||||
fill++;
|
||||
}
|
||||
@@ -824,7 +846,7 @@ export default function Home() {
|
||||
}
|
||||
|
||||
return items;
|
||||
}, [shuffled, widgets]);
|
||||
}, [spaced, widgets]);
|
||||
|
||||
const gridRows: (typeof gridItems)[] = useMemo(() => {
|
||||
const rows: (typeof gridItems)[] = [];
|
||||
|
||||
Reference in New Issue
Block a user