Prevent ads from appearing next to important content widgets
Adjust the ad placement logic to ensure ads are only inserted into rows that do not contain widgets, preventing conflicts with existing content. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 517dfa7b-26ac-463d-a6e1-a58c6df97188 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: 0c1f949a-c832-41db-8b87-2202fbfe628b 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:
parent
f099ce8093
commit
e10aa417c1
BIN
attached_assets/image_1772472424144.png
Normal file
BIN
attached_assets/image_1772472424144.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 556 KiB |
@ -491,16 +491,21 @@ export default function Home() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const totalRows = items.length / 4;
|
const totalRows = items.length / 4;
|
||||||
const adRows = [1, 3, 5, 7];
|
let adCount = 0;
|
||||||
const adCols = [3, 1, 2, 0];
|
for (let row = 0; row < totalRows && adCount < 4; row++) {
|
||||||
adRows.forEach((row, i) => {
|
const rowStart = row * 4;
|
||||||
if (row < totalRows) {
|
const rowItems = items.slice(rowStart, rowStart + 4);
|
||||||
const idx = row * 4 + adCols[i % adCols.length];
|
const hasWidget = rowItems.some((it) => it.type === "widget");
|
||||||
if (items[idx] && items[idx].type === "article") {
|
if (hasWidget) continue;
|
||||||
items[idx] = { type: "ad", key: `ad-${i}` };
|
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;
|
return items;
|
||||||
}, [shuffled, widgets]);
|
}, [shuffled, widgets]);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user