Skip to content

Commit 0106355

Browse files
committed
Fix toggle button
1 parent af8b2ff commit 0106355

File tree

2 files changed

+39
-11
lines changed

2 files changed

+39
-11
lines changed

src/templates/base.jinja

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!DOCTYPE html>
2-
<html lang="en" class="light">
2+
<html lang="en" class="">
33
<head>
44
<meta charset="UTF-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
@@ -36,6 +36,15 @@
3636
{% block title %}Git ingest{% endblock %}
3737
</title>
3838
<script src="https://cdn.tailwindcss.com"></script>
39+
<!-- Add Tailwind configuration right after loading Tailwind -->
40+
<script>
41+
tailwind.config = {
42+
darkMode: 'class', // Enable class-based dark mode
43+
theme: {
44+
extend: {}
45+
}
46+
}
47+
</script>
3948
<script src="/static/js/utils.js"></script>
4049
<script src="/static/js/snow.js"></script>
4150
<style>

src/templates/components/navbar.jinja

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,15 @@
2323
2424
// Dark mode toggle functionality
2525
function initDarkMode() {
26-
const isDark = localStorage.getItem('darkMode') === 'true' ||
26+
// Check if user has previously set a preference
27+
const isDark = localStorage.getItem('darkMode') === 'true' ||
2728
(!localStorage.getItem('darkMode') && window.matchMedia('(prefers-color-scheme: dark)').matches);
28-
29-
document.documentElement.classList.toggle('dark', isDark);
29+
30+
if (isDark) {
31+
document.documentElement.classList.add('dark');
32+
} else {
33+
document.documentElement.classList.remove('dark');
34+
}
3035
updateDarkModeIcon(isDark);
3136
}
3237
@@ -39,7 +44,7 @@
3944
function updateDarkModeIcon(isDark) {
4045
const moonIcon = document.getElementById('moon-icon');
4146
const sunIcon = document.getElementById('sun-icon');
42-
47+
4348
if (isDark) {
4449
moonIcon.classList.add('hidden');
4550
sunIcon.classList.remove('hidden');
@@ -50,7 +55,11 @@
5055
}
5156
5257
// Initialize dark mode on page load
53-
document.addEventListener('DOMContentLoaded', initDarkMode);
58+
if (document.readyState === 'loading') {
59+
document.addEventListener('DOMContentLoaded', initDarkMode);
60+
} else {
61+
initDarkMode();
62+
}
5463
</script>
5564
<header class="sticky top-0 bg-[#FFFDF8] dark:bg-gray-900 border-b-[3px] border-gray-900 dark:border-gray-400 z-50">
5665
<div class="max-w-4xl mx-auto px-4">
@@ -90,16 +99,26 @@
9099
<span id="github-stars">0</span>
91100
</div>
92101
</div>
93-
<button onclick="toggleDarkMode()"
102+
<button onclick="toggleDarkMode()"
94103
class="p-2 rounded-lg hover:bg-gray-200 dark:hover:bg-gray-700 transition-colors"
95104
aria-label="Toggle dark mode">
96105
<!-- Moon icon -->
97-
<svg id="moon-icon" class="w-5 h-5 text-gray-900 dark:text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
98-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z"></path>
106+
<svg id="moon-icon"
107+
class="w-5 h-5 text-gray-900 dark:text-white"
108+
fill="none"
109+
stroke="currentColor"
110+
viewBox="0 0 24 24">
111+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z">
112+
</path>
99113
</svg>
100114
<!-- Sun icon -->
101-
<svg id="sun-icon" class="hidden w-5 h-5 text-gray-900 dark:text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
102-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z"></path>
115+
<svg id="sun-icon"
116+
class="hidden w-5 h-5 text-gray-900 dark:text-white"
117+
fill="none"
118+
stroke="currentColor"
119+
viewBox="0 0 24 24">
120+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z">
121+
</path>
103122
</svg>
104123
</button>
105124
</nav>

0 commit comments

Comments
 (0)