This commit is contained in:
2025-01-20 12:59:34 +02:00
parent 2a7a895e11
commit 396549c850
3 changed files with 34 additions and 38 deletions

View File

@@ -3,7 +3,8 @@ title: "Header"
insert_anchor_links: "left"
template: "partials/header.html"
extra:
logoPath: "images/new_logo_tft_light.png"
logoPathLight: "images/new_logo_tft_light.png"
logoPathDark: "images/new_logo_tft_dark.png"
---

View File

@@ -194,36 +194,32 @@ document.getElementById("year").innerHTML = new Date().getFullYear();
// Get the toggle switch and the logo element
const toggleSwitch = document.getElementById('darkModeSwitch');
const siteLogo = document.getElementById('site-logo');
// Apply the saved theme on load
document.addEventListener('DOMContentLoaded', () => {
const toggleSwitch = document.getElementById('darkModeSwitch');
const logo = document.getElementById('logo');
// Log the current state for debugging
console.log('Light logo:', logo.getAttribute('data-light-logo'));
console.log('Dark logo:', logo.getAttribute('data-dark-logo'));
const savedTheme = localStorage.getItem('theme');
if (savedTheme === 'dark') {
document.body.classList.add('dark-mode');
toggleSwitch.checked = true;
logo.src = logo.getAttribute('data-dark-logo');
console.log('Loaded dark mode with dark logo.');
siteLogo.src = siteLogo.getAttribute('data-dark');
} else {
logo.src = logo.getAttribute('data-light-logo');
console.log('Loaded light mode with light logo.');
document.body.classList.remove('dark-mode');
siteLogo.src = siteLogo.getAttribute('data-light');
}
});
toggleSwitch.addEventListener('change', () => {
// Toggle dark mode
toggleSwitch.addEventListener('change', () => {
if (toggleSwitch.checked) {
document.body.classList.add('dark-mode');
localStorage.setItem('theme', 'dark');
logo.src = logo.getAttribute('data-dark-logo');
console.log('Switched to dark mode. Updated logo to dark.');
siteLogo.src = siteLogo.getAttribute('data-dark');
} else {
document.body.classList.remove('dark-mode');
localStorage.setItem('theme', 'light');
logo.src = logo.getAttribute('data-light-logo');
console.log('Switched to light mode. Updated logo to light.');
siteLogo.src = siteLogo.getAttribute('data-light');
}
});
});

View File

@@ -7,14 +7,13 @@
<div class="mx-auto container flex z-50 justify-between items-center px-6 sm:px-4 md:px-6 py-4 lg:px-5 lg:justify-start space-x-10 sm:space-x-4 ">
<a href="{{ get_url(path='/') }}" class="flex">
<img
id="logo"
id="site-logo"
class="w-36 h-auto"
style="max-width: none;"
src="{{ get_url(path=section.extra.logoPathLight) }}"
data-light-logo="{{ get_url(path=section.extra.logoPathLight) }}"
data-dark-logo="{{ get_url(path=section.extra.logoPathDark) }}"
alt="ThreeFold Logo"
/>
data-light="{{ get_url(path=section.extra.logoPathLight) }}"
data-dark="{{ get_url(path=section.extra.logoPathDark) }}"
alt="ThreeFold Logo" />
</a>
</a>