Place advertisements in available slots within the blog post grid
Adjust logic to insert advertisements into the grid layout, ensuring they replace article items in available spaces. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 517dfa7b-26ac-463d-a6e1-a58c6df97188 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: c2b371a0-acc5-4b7b-8486-089b44132f2c 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
3b503ed961
commit
c4da507bc9
BIN
attached_assets/image_1772475024743.png
Normal file
BIN
attached_assets/image_1772475024743.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 433 KiB |
@ -483,15 +483,17 @@ export default function Home() {
|
||||
|
||||
const totalRows = items.length / 4;
|
||||
const adRows = [1, 3, 5, 7];
|
||||
const adCols = [3, 1, 2, 0];
|
||||
adRows.forEach((row, i) => {
|
||||
if (row < totalRows) {
|
||||
const idx = row * 4 + adCols[i % adCols.length];
|
||||
if (items[idx] && items[idx].type === "article") {
|
||||
items[idx] = { type: "ad", key: `ad-${i}` };
|
||||
let adCount = 0;
|
||||
for (const row of adRows) {
|
||||
if (row >= totalRows) continue;
|
||||
const rowStart = row * 4;
|
||||
for (let col = 3; col >= 0; col--) {
|
||||
if (items[rowStart + col] && items[rowStart + col].type === "article") {
|
||||
items[rowStart + col] = { type: "ad", key: `ad-${adCount++}` };
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return items;
|
||||
}, [shuffled, widgets]);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user