diff --git a/attached_assets/image_1772472424144.png b/attached_assets/image_1772472424144.png new file mode 100644 index 0000000..88c3afd Binary files /dev/null and b/attached_assets/image_1772472424144.png differ diff --git a/client/src/pages/home.tsx b/client/src/pages/home.tsx index e4d7065..6e2035e 100644 --- a/client/src/pages/home.tsx +++ b/client/src/pages/home.tsx @@ -491,16 +491,21 @@ export default function Home() { } const totalRows = items.length / 4; - const adRows = [1, 3, 5, 7]; - const adCols = [3, 1, 2, 0]; - adRows.forEach((row, i) => { - if (row < totalRows) { - const idx = row * 4 + adCols[i % adCols.length]; - if (items[idx] && items[idx].type === "article") { - items[idx] = { type: "ad", key: `ad-${i}` }; - } + let adCount = 0; + for (let row = 0; row < totalRows && adCount < 4; row++) { + const rowStart = row * 4; + const rowItems = items.slice(rowStart, rowStart + 4); + const hasWidget = rowItems.some((it) => it.type === "widget"); + if (hasWidget) continue; + const articleIndices = rowItems + .map((it, ci) => (it.type === "article" ? ci : -1)) + .filter((ci) => ci >= 0); + if (articleIndices.length > 0) { + const col = articleIndices[adCount % articleIndices.length]; + items[rowStart + col] = { type: "ad", key: `ad-${adCount}` }; + adCount++; } - }); + } return items; }, [shuffled, widgets]);