mirror of
https://github.com/tiennm99/bonsai.git
synced 2026-05-28 14:21:07 +00:00
16326d059d
Bundle of four small additions for the v0.2 release. All strictly additive — no breaking changes; v0.1 sites upgrade without edits. Phase 1 — Color theme presets - Refactor static/css/bonsai.css: palette vars now scoped per [data-bonsai-theme]; layout vars (radius/gap/pad/fonts) stay in :root - Four palettes: bonsai (default, vermilion+washi), sakura (cherry blossom), sumi (monochrome ink), koi (orange+cream). Light + dark variants each, both prefers-color-scheme and manual data-theme override - New params.colorTheme (default 'bonsai'); applied via baseof - Themes gallery at exampleSite /themes/ shows all 4 side-by-side Phase 2 — schema.org Person markup - New layouts/partials/schema-person.html emits JSON-LD ProfilePage containing a Person (built from name/bio/avatar/links + optional jobTitle/location/email) - mailto: and tel: links excluded from sameAs - Suppress with params.schema = false - Wired into head.html Phase 3 — Theme toggle UI button - New layouts/partials/theme-toggle-button.html (sun/moon SVGs) - Rendered in footer when params.themeToggle = true - aria-pressed reflects current state; updated theme-toggle.js to sync on click and on first paint - Sun shown in dark mode, moon in light (button shows target state) - exampleSite enables the toggle by default for demo Phase 4 — Avatar initials fallback - New layouts/partials/avatar.html: img if params.avatar set, inline SVG circle with initials otherwise - Initials auto-derived from params.name (first letter of up to 2 words, uppercased); override with params.avatarInitials - Background overrideable with params.avatarBg; defaults to accent - bio-card.html simplified to delegate to the partial
27 lines
857 B
JavaScript
27 lines
857 B
JavaScript
// Loaded only when params.themeToggle = true.
|
|
// Persists user preference and overrides system color-scheme.
|
|
(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;
|
|
|
|
function syncPressed() {
|
|
const isDark = root.dataset.theme === 'dark'
|
|
|| (root.dataset.theme === 'auto' && matchMedia('(prefers-color-scheme: dark)').matches);
|
|
btn.setAttribute('aria-pressed', String(isDark));
|
|
}
|
|
|
|
syncPressed();
|
|
|
|
btn.addEventListener('click', () => {
|
|
const next = root.dataset.theme === 'dark' ? 'light' : 'dark';
|
|
root.dataset.theme = next;
|
|
localStorage.setItem(KEY, next);
|
|
syncPressed();
|
|
});
|
|
})();
|