diff --git a/client/src/pages/home.tsx b/client/src/pages/home.tsx index a17f91a..bc4709c 100644 --- a/client/src/pages/home.tsx +++ b/client/src/pages/home.tsx @@ -491,10 +491,20 @@ export default function Home() { } const totalRows = items.length / 4; - const adTargetRows = [1, 3, 5, 7]; + const widgetRowSet = new Set(); + for (let row = 0; row < totalRows; row++) { + const rowStart = row * 4; + const rowItems = items.slice(rowStart, rowStart + 4); + if (rowItems.some((it) => it.type === "widget")) { + widgetRowSet.add(row); + } + } + let adCount = 0; - for (const row of adTargetRows) { - if (row >= totalRows) continue; + for (let row = 0; row < totalRows && adCount < 4; row++) { + if (widgetRowSet.has(row)) continue; + if (widgetRowSet.has(row + 1)) continue; + if (widgetRowSet.has(row - 1)) continue; const rowStart = row * 4; const rowItems = items.slice(rowStart, rowStart + 4); const articleIndices = rowItems