Add dark mode toggle with localStorage persistence#136
Draft
Add dark mode toggle with localStorage persistence#136
Conversation
✅ Deploy Preview for kausalflow-tools ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Co-authored-by: emptymalei <663798+emptymalei@users.noreply.github.com>
Co-authored-by: emptymalei <663798+emptymalei@users.noreply.github.com>
Co-authored-by: emptymalei <663798+emptymalei@users.noreply.github.com>
Co-authored-by: emptymalei <663798+emptymalei@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add dark mode feature for better low light usability
Add dark mode toggle with localStorage persistence
Dec 22, 2025
There was a problem hiding this comment.
Pull request overview
Adds a dark mode toggle that swaps between Bulmaswatch “light/dark” variants and persists the user’s choice in localStorage, with an inline synchronous initialization to avoid FOUC.
Changes:
- Injects a theme stylesheet early (via inline script) based on validated
localStoragepreference. - Adds JS helpers to toggle theme, persist preference, and update the toggle icon.
- Adds a navbar toggle control (moon/sun icon) gated by
theme_variantconfiguration.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
layouts/_default/baseof.html |
Adds synchronous theme stylesheet injection + toggle logic and icon initialization. |
layouts/partials/menu.html |
Adds a navbar theme toggle control shown when theme_variant is configured. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+47
to
+48
| var lightTheme = '{{.Site.Params.theme_variant.light}}'; | ||
| var darkTheme = '{{.Site.Params.theme_variant.dark}}'; |
Comment on lines
+100
to
+101
| var LIGHT_THEME = '{{.Site.Params.theme_variant.light}}'; | ||
| var DARK_THEME = '{{.Site.Params.theme_variant.dark}}'; |
| var themeUrl = 'https://jenil.github.io/bulmaswatch/' + (validTheme === 'dark' ? darkTheme : lightTheme) + '/bulmaswatch.min.css'; | ||
| document.write('<link rel="stylesheet" id="theme-stylesheet" href="' + themeUrl + '">'); | ||
| })(); | ||
| </script> |
Comment on lines
+113
to
+118
| <a class="navbar-item tooltip" id="theme-toggle" onclick="toggleTheme()" style="cursor: pointer;"> | ||
| <span class="icon"> | ||
| <i class="fas fa-moon"></i> | ||
| </span> | ||
| <span class="tooltiptext">Toggle Dark Mode</span> | ||
| </a> |
Comment on lines
+99
to
+138
| // Dark mode toggle functionality | ||
| var LIGHT_THEME = '{{.Site.Params.theme_variant.light}}'; | ||
| var DARK_THEME = '{{.Site.Params.theme_variant.dark}}'; | ||
|
|
||
| function getThemeUrl(theme) { | ||
| var validTheme = (theme === 'dark' || theme === 'light') ? theme : 'light'; | ||
| return 'https://jenil.github.io/bulmaswatch/' + (validTheme === 'dark' ? DARK_THEME : LIGHT_THEME) + '/bulmaswatch.min.css'; | ||
| } | ||
|
|
||
| function toggleTheme() { | ||
| var currentTheme = localStorage.getItem('theme') || 'light'; | ||
| var newTheme = currentTheme === 'light' ? 'dark' : 'light'; | ||
|
|
||
| document.getElementById('theme-stylesheet').href = getThemeUrl(newTheme); | ||
| localStorage.setItem('theme', newTheme); | ||
|
|
||
| // Update icon | ||
| updateThemeIcon(newTheme); | ||
| } | ||
|
|
||
| function updateThemeIcon(theme) { | ||
| var validTheme = (theme === 'dark' || theme === 'light') ? theme : 'light'; | ||
| var themeToggle = document.getElementById('theme-toggle'); | ||
| if (themeToggle) { | ||
| var icon = themeToggle.querySelector('i'); | ||
| if (icon) { | ||
| if (validTheme === 'dark') { | ||
| icon.className = 'fas fa-sun'; | ||
| } else { | ||
| icon.className = 'fas fa-moon'; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Initialize theme icon on page load | ||
| document.addEventListener('DOMContentLoaded', function() { | ||
| var currentTheme = localStorage.getItem('theme') || 'light'; | ||
| updateThemeIcon(currentTheme); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements dark mode switching using existing Bulmaswatch theme variants (journal/darkly) configured in
config.yaml.Changes
Dynamic theme loading (
layouts/_default/baseof.html)getThemeUrl()helper for theme URL constructiontoggleTheme()switches between light/dark, updates stylesheet hrefupdateThemeIcon()updates toggle button icon (moon ↔ sun)Toggle button (
layouts/partials/menu.html)Implementation notes
Uses
document.write()intentionally for synchronous execution during page parse to avoid FOUC. Theme values from Hugo config are server-side safe; only user input (localStorage) is validated.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
jenil.github.io/usr/bin/curl curl -s REDACTED(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.