Skip to content

Commit eabf46a

Browse files
author
OpenClaw Sync
committed
Fix theme toggle: SVG icons, cache bust JS, no emoji
1 parent f0d0cb4 commit eabf46a

2 files changed

Lines changed: 26 additions & 18 deletions

File tree

_layouts/default.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<a href="{{ "/blog/" | relative_url }}" {% if page.url == "/blog/" %}aria-current="page"{% endif %}>Blog</a>
1313
<a href="{{ "/about/" | relative_url }}" {% if page.url == "/about/" %}aria-current="page"{% endif %}>About</a>
1414
<a href="{{ "/contact/" | relative_url }}" {% if page.url == "/contact/" %}aria-current="page"{% endif %}>Contact</a>
15-
<button class="theme-toggle" id="theme-toggle" aria-label="Toggle dark mode">☀️</button>
15+
<button class="theme-toggle" id="theme-toggle" aria-label="Toggle dark mode"></button>
1616
</nav>
1717
</header>
1818

@@ -24,6 +24,6 @@
2424
<p>© {{ "now" | date: "%Y" }} Devin Bernosky.</p>
2525
</footer>
2626
</div>
27-
<script src="{{ "/assets/js/main.js" | relative_url }}" defer></script>
27+
<script src="{{ "/assets/js/main.js?v=2" | relative_url }}" defer></script>
2828
</body>
2929
</html>

assets/js/main.js

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,46 @@
1-
document.addEventListener('DOMContentLoaded', () => {
1+
document.addEventListener('DOMContentLoaded', function() {
2+
// SVG icons
3+
var sun = '<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5"><circle cx="8" cy="8" r="3.5"/><line x1="8" y1="1" x2="8" y2="3"/><line x1="8" y1="13" x2="8" y2="15"/><line x1="1" y1="8" x2="3" y2="8"/><line x1="13" y1="8" x2="15" y2="8"/><line x1="3.05" y1="3.05" x2="4.46" y2="4.46"/><line x1="11.54" y1="11.54" x2="12.95" y2="12.95"/><line x1="3.05" y1="12.95" x2="4.46" y2="11.54"/><line x1="11.54" y1="4.46" x2="12.95" y2="3.05"/></svg>';
4+
var moon = '<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5"><path d="M13.5 8.5a5.5 5.5 0 0 1-7-7 5.5 5.5 0 1 0 7 7z"/></svg>';
5+
26
// Theme toggle
3-
const toggle = document.getElementById('theme-toggle');
4-
const update = () => {
5-
const isDark = document.documentElement.getAttribute('data-theme') === 'dark';
6-
toggle.textContent = isDark ? '☀️' : '🌙';
7-
};
8-
9-
toggle.addEventListener('click', () => {
10-
const isDark = document.documentElement.getAttribute('data-theme') === 'dark';
11-
const next = isDark ? 'light' : 'dark';
7+
var toggle = document.getElementById('theme-toggle');
8+
if (!toggle) return;
9+
10+
function isDark() {
11+
return document.documentElement.getAttribute('data-theme') === 'dark';
12+
}
13+
14+
function updateIcon() {
15+
toggle.innerHTML = isDark() ? sun : moon;
16+
}
17+
18+
toggle.addEventListener('click', function() {
19+
var next = isDark() ? 'light' : 'dark';
1220
document.documentElement.setAttribute('data-theme', next);
1321
localStorage.setItem('theme', next);
14-
update();
22+
updateIcon();
1523
});
1624

17-
update();
25+
updateIcon();
1826

1927
// Back to top button
20-
const topBtn = document.createElement('a');
28+
var topBtn = document.createElement('a');
2129
topBtn.href = '#';
2230
topBtn.className = 'back-to-top';
2331
topBtn.setAttribute('aria-label', 'Back to top');
24-
topBtn.textContent = '';
32+
topBtn.textContent = '\u2191';
2533
document.body.appendChild(topBtn);
2634

27-
window.addEventListener('scroll', () => {
35+
window.addEventListener('scroll', function() {
2836
if (window.scrollY > 400) {
2937
topBtn.classList.add('visible');
3038
} else {
3139
topBtn.classList.remove('visible');
3240
}
3341
}, { passive: true });
3442

35-
topBtn.addEventListener('click', (e) => {
43+
topBtn.addEventListener('click', function(e) {
3644
e.preventDefault();
3745
window.scrollTo({ top: 0, behavior: 'smooth' });
3846
});

0 commit comments

Comments
 (0)