Adjust ad placement to avoid displaying ads near content widgets

Modify the logic for inserting advertisements to ensure they are not placed directly adjacent to any content widgets, preventing visual clutter and improving the user experience on the homepage.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 517dfa7b-26ac-463d-a6e1-a58c6df97188
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Event-Id: 469e25c3-fbc6-4f2b-8d23-588f0b8328dc
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/f209e72a-0939-48fa-84fc-57854de71967/517dfa7b-26ac-463d-a6e1-a58c6df97188/nFw7xof
Replit-Helium-Checkpoint-Created: true
This commit is contained in:
sebastjanartic 2026-03-02 17:53:02 +00:00
parent 4704759224
commit c02d93cad8

View File

@ -491,10 +491,20 @@ export default function Home() {
}
const totalRows = items.length / 4;
const adTargetRows = [1, 3, 5, 7];
const widgetRowSet = new Set<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);
}
}
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