diff --git a/client/src/pages/home.tsx b/client/src/pages/home.tsx index bc4709c..0ad5a58 100644 --- a/client/src/pages/home.tsx +++ b/client/src/pages/home.tsx @@ -491,30 +491,20 @@ export default function Home() { } const totalRows = items.length / 4; - const widgetRowSet = new Set(); + let adCount = 0; + const articleOnlyRows: number[] = []; 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); + if (rowItems.every((it) => it.type === "article")) { + articleOnlyRows.push(row); } } - - let adCount = 0; - 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; + for (let i = 0; i < articleOnlyRows.length && adCount < 4; i += 2) { + const row = articleOnlyRows[i]; const rowStart = row * 4; - const rowItems = items.slice(rowStart, rowStart + 4); - const articleIndices = rowItems - .map((it, ci) => (it.type === "article" ? ci : -1)) - .filter((ci) => ci >= 0); - if (articleIndices.length > 0) { - const col = articleIndices[0]; - items[rowStart + col] = { type: "ad", key: `ad-${adCount}` }; - adCount++; - } + items[rowStart] = { type: "ad", key: `ad-${adCount}` }; + adCount++; } return items;