feat: add theme dark / light + add base content

This commit is contained in:
2024-11-30 18:21:15 +01:00
parent 5fb1e058cd
commit 08a08b9b06
13 changed files with 424 additions and 58 deletions

28
assets/theme-toggle.js Normal file
View File

@@ -0,0 +1,28 @@
// Function to switch theme
const toggleTheme = () => {
const currentTheme = document.documentElement.getAttribute('data-theme');
const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
// Set the new theme to the root element
document.documentElement.setAttribute('data-theme', newTheme);
// Store the theme preference in localStorage
localStorage.setItem('theme', newTheme);
// Update the button icon
document.getElementById('theme-toggle').textContent = newTheme === 'dark' ? '🌙' : '🌞';
};
// Check for saved theme preference in localStorage
const savedTheme = localStorage.getItem('theme');
if (savedTheme) {
document.documentElement.setAttribute('data-theme', savedTheme);
document.getElementById('theme-toggle').textContent = savedTheme === 'dark' ? '🌙' : '🌞';
} else {
// Default to light theme if no preference is saved
document.documentElement.setAttribute('data-theme', 'light');
document.getElementById('theme-toggle').textContent = '🌞';
}
// Add event listener for the theme toggle button
document.getElementById('theme-toggle').addEventListener('click', toggleTheme);