Files
bonsai/static/js/theme-toggle.js
T
tiennm99 a1dc82f213 feat: initial Bonsai theme scaffold
Minimalist Hugo theme for link-in-bio pages, inspired by Linktree
and Japanese bonsai aesthetics.

- Single-page bio with avatar, tagline, bio, and links
- Data-driven via [params] in hugo.toml — no content files needed
- Light/dark mode via prefers-color-scheme + optional toggle
- Inline SVG icon set (github, globe, mail, twitter, linkedin, etc)
- Zero JS by default; opt-in theme toggle script
- exampleSite for local development
2026-05-01 10:04:59 +07:00

18 lines
607 B
JavaScript

// Optional: enable via params.themeToggle = true in hugo.toml
// Persists user preference and overrides system theme.
(function () {
const KEY = 'bonsai-theme';
const root = document.documentElement;
const saved = localStorage.getItem(KEY);
if (saved === 'light' || saved === 'dark') root.dataset.theme = saved;
const btn = document.querySelector('[data-bonsai-theme-toggle]');
if (!btn) return;
btn.addEventListener('click', () => {
const current = root.dataset.theme === 'dark' ? 'light' : 'dark';
root.dataset.theme = current;
localStorage.setItem(KEY, current);
});
})();