fix: Resolve home page latency, add robust language validation and testimonial fallback

This commit is contained in:
2025-12-07 20:02:42 +01:00
parent e3bf169221
commit 41f363eb27
4 changed files with 107 additions and 23 deletions

View File

@@ -80,31 +80,48 @@
{% block extra_js %}
<script>
let testimonials = [];
let currentIndex = 0;
let testimonials = [];
let currentIndex = 0;
fetch('/static/data/testimonials.{{ lang }}.json')
.then(res => res.json())
.then(data => {
testimonials = data;
showTestimonial(0);
setInterval(nextTestimonial, 8000);
});
fetch('/static/data/testimonials.{{ lang }}.json')
.then(res => {
if (!res.ok) throw new Error("Testimonials not found");
return res.json();
})
.then(data => {
testimonials = data;
showTestimonial(0);
setInterval(nextTestimonial, 8000);
})
.catch(err => {
console.warn("Testimonials load failed for '{{ lang }}':", err);
// Fallback to German
if ("{{ lang }}" !== "de") {
fetch('/static/data/testimonials.de.json')
.then(res => res.json())
.then(data => {
testimonials = data;
showTestimonial(0);
setInterval(nextTestimonial, 8000);
})
.catch(e => console.error("Fallback testimonials failed:", e));
}
});
function showTestimonial(index) {
const t = testimonials[index];
document.getElementById('testimonial-text').textContent = `"${t.message}"`;
document.getElementById('testimonial-author').textContent = ` ${t.author}, ${t.role}`;
}
function showTestimonial(index) {
const t = testimonials[index];
document.getElementById('testimonial-text').textContent = `"${t.message}"`;
document.getElementById('testimonial-author').textContent = ` ${t.author}, ${t.role}`;
}
function nextTestimonial() {
currentIndex = (currentIndex + 1) % testimonials.length;
showTestimonial(currentIndex);
}
function nextTestimonial() {
currentIndex = (currentIndex + 1) % testimonials.length;
showTestimonial(currentIndex);
}
function prevTestimonial() {
currentIndex = (currentIndex - 1 + testimonials.length) % testimonials.length;
showTestimonial(currentIndex);
}
function prevTestimonial() {
currentIndex = (currentIndex - 1 + testimonials.length) % testimonials.length;
showTestimonial(currentIndex);
}
</script>
{% endblock %}
{% endblock %}