Improve ad placement and fix display issues on the homepage
Modify ad insertion logic on the homepage to prevent ads from appearing in the same row and update image URLs in the gallery data. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 517dfa7b-26ac-463d-a6e1-a58c6df97188 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: e238672d-f0b8-42f8-b206-9c933e38a0b7 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:
+13
-12
@@ -499,27 +499,28 @@ export default function Home() {
|
||||
items.push({ type: "article", key: `a-${shuffled[ai].id}`, article: shuffled[ai++] });
|
||||
}
|
||||
|
||||
const adPositions = [3, 9, 17, 23];
|
||||
let adIdx = 0;
|
||||
for (const pos of adPositions) {
|
||||
if (pos <= items.length) {
|
||||
items.splice(pos, 0, { type: "ad", key: `ad-${adIdx++}` });
|
||||
}
|
||||
}
|
||||
|
||||
const remainder = items.length % 4;
|
||||
if (remainder > 0 && shuffled.length > 0) {
|
||||
let fill = 0;
|
||||
const usedIds = new Set(items.filter(i => i.article).map(i => i.article!.id));
|
||||
const fillPool = shuffled.filter(a => !usedIds.has(a.id));
|
||||
while (items.length % 4 !== 0) {
|
||||
const src = fillPool.length > 0 ? fillPool : shuffled;
|
||||
const art = src[fill % src.length];
|
||||
const art = shuffled[fill % shuffled.length];
|
||||
items.push({ type: "article", key: `fill-${fill}`, article: art });
|
||||
fill++;
|
||||
}
|
||||
}
|
||||
|
||||
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}` };
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return items;
|
||||
}, [shuffled, widgets]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user