mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-01 10:14:59 +00:00
fix: prevent recently removed testimonials from immediate reuse
This commit is contained in:
parent
589cb2ac79
commit
a98ca30438
1 changed files with 42 additions and 10 deletions
|
@ -664,20 +664,40 @@ aider --model gpt-4o --api-key openai=your-key-goes-here</pre>
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to update a single testimonial
|
// Function to update a single testimonial
|
||||||
function updateSingleTestimonial(index) {
|
function updateSingleTestimonial(index, recentlyRemoved = []) {
|
||||||
// Get a new testimonial not currently displayed
|
// Get a new testimonial not currently displayed and not recently removed
|
||||||
const remainingTestimonials = testimonials.filter(
|
const remainingTestimonials = testimonials.filter(t => {
|
||||||
t => !initialTestimonials.some(it => it.author === t.author && it.text === t.text)
|
// Not currently displayed in any card
|
||||||
);
|
const notCurrentlyDisplayed = !initialTestimonials.some(
|
||||||
|
it => it.author === t.author && it.text === t.text
|
||||||
|
);
|
||||||
|
|
||||||
|
// Not in the recently removed list
|
||||||
|
const notRecentlyRemoved = !recentlyRemoved.some(
|
||||||
|
rt => rt.author === t.author && rt.text === t.text
|
||||||
|
);
|
||||||
|
|
||||||
|
return notCurrentlyDisplayed && notRecentlyRemoved;
|
||||||
|
});
|
||||||
|
|
||||||
let newTestimonial;
|
let newTestimonial;
|
||||||
if (remainingTestimonials.length > 0) {
|
if (remainingTestimonials.length > 0) {
|
||||||
const randomIndex = Math.floor(Math.random() * remainingTestimonials.length);
|
const randomIndex = Math.floor(Math.random() * remainingTestimonials.length);
|
||||||
newTestimonial = remainingTestimonials[randomIndex];
|
newTestimonial = remainingTestimonials[randomIndex];
|
||||||
} else {
|
} else {
|
||||||
// If we've used all testimonials, pick a random one
|
// If we've used all available testimonials, pick a random one that's at least not currently displayed
|
||||||
const randomIndex = Math.floor(Math.random() * testimonials.length);
|
const notDisplayed = testimonials.filter(
|
||||||
newTestimonial = testimonials[randomIndex];
|
t => !initialTestimonials.some(it => it.author === t.author && it.text === t.text)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (notDisplayed.length > 0) {
|
||||||
|
const randomIndex = Math.floor(Math.random() * notDisplayed.length);
|
||||||
|
newTestimonial = notDisplayed[randomIndex];
|
||||||
|
} else {
|
||||||
|
// Absolute fallback - just pick any random testimonial
|
||||||
|
const randomIndex = Math.floor(Math.random() * testimonials.length);
|
||||||
|
newTestimonial = testimonials[randomIndex];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace the testimonial at the given index
|
// Replace the testimonial at the given index
|
||||||
|
@ -709,6 +729,9 @@ aider --model gpt-4o --api-key openai=your-key-goes-here</pre>
|
||||||
// Track the last flipped card index to avoid repeats
|
// Track the last flipped card index to avoid repeats
|
||||||
let lastFlippedIndex = -1;
|
let lastFlippedIndex = -1;
|
||||||
|
|
||||||
|
// Track recently removed testimonials to prevent immediate reuse
|
||||||
|
let recentlyRemovedTestimonials = [];
|
||||||
|
|
||||||
// Rotate one testimonial at a time, randomly selecting which one to change
|
// Rotate one testimonial at a time, randomly selecting which one to change
|
||||||
setInterval(function() {
|
setInterval(function() {
|
||||||
// Select a random index that's different from the last flipped one
|
// Select a random index that's different from the last flipped one
|
||||||
|
@ -717,8 +740,17 @@ aider --model gpt-4o --api-key openai=your-key-goes-here</pre>
|
||||||
randomIndex = Math.floor(Math.random() * displayCount);
|
randomIndex = Math.floor(Math.random() * displayCount);
|
||||||
} while (randomIndex === lastFlippedIndex && displayCount > 1);
|
} while (randomIndex === lastFlippedIndex && displayCount > 1);
|
||||||
|
|
||||||
// Update the selected testimonial
|
// Store the testimonial being removed to prevent immediate reuse
|
||||||
updateSingleTestimonial(randomIndex);
|
const removedTestimonial = initialTestimonials[randomIndex];
|
||||||
|
recentlyRemovedTestimonials.push(removedTestimonial);
|
||||||
|
|
||||||
|
// Limit the recently removed list to avoid depleting the pool too much
|
||||||
|
if (recentlyRemovedTestimonials.length > 3) {
|
||||||
|
recentlyRemovedTestimonials.shift(); // Remove oldest entry
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the selected testimonial, passing the list of testimonials to avoid
|
||||||
|
updateSingleTestimonial(randomIndex, recentlyRemovedTestimonials);
|
||||||
|
|
||||||
// Store this index as the last flipped
|
// Store this index as the last flipped
|
||||||
lastFlippedIndex = randomIndex;
|
lastFlippedIndex = randomIndex;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue