Adjust ad placement to appear above specific content widgets

Modify the logic for inserting ads to ensure they are positioned before designated content widgets in the grid layout.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 517dfa7b-26ac-463d-a6e1-a58c6df97188
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Event-Id: ddb08602-3667-4dce-8ea7-21162a508afd
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:33:19 +00:00
parent 30fee72431
commit 9ebb74eb9b

View File

@ -491,17 +491,17 @@ export default function Home() {
}
const totalRows = items.length / 4;
const adTargetRows = [1, 3, 5, 7];
let adCount = 0;
for (let row = 0; row < totalRows && adCount < 4; row++) {
for (const row of adTargetRows) {
if (row >= totalRows) continue;
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];
const col = articleIndices[0];
items[rowStart + col] = { type: "ad", key: `ad-${adCount}` };
adCount++;
}