Skip to content

Add dark mode toggle with localStorage persistence#136

Draft
Copilot wants to merge 5 commits intomasterfrom
copilot/add-dark-mode-support
Draft

Add dark mode toggle with localStorage persistence#136
Copilot wants to merge 5 commits intomasterfrom
copilot/add-dark-mode-support

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 22, 2025

Implements dark mode switching using existing Bulmaswatch theme variants (journal/darkly) configured in config.yaml.

Changes

  • Dynamic theme loading (layouts/_default/baseof.html)

    • Synchronous theme initialization from localStorage to prevent FOUC
    • getThemeUrl() helper for theme URL construction
    • toggleTheme() switches between light/dark, updates stylesheet href
    • updateThemeIcon() updates toggle button icon (moon ↔ sun)
    • XSS protection: validates localStorage value to only accept 'light' or 'dark'
  • Toggle button (layouts/partials/menu.html)

    • Moon icon in light mode, sun icon in dark mode
    • Positioned after Facebook icon in navbar

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.

// Validates and defaults to light mode
var savedTheme = localStorage.getItem('theme');
var validTheme = (savedTheme === 'dark' || savedTheme === 'light') ? savedTheme : 'light';
Reference design showing dark mode implementation: ![Dark mode reference](https://github.com/kausalflow/tools/assets/663798/f5856e0e-3237-43d4-a569-885c54b71e2d)

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
    • Triggering command: /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

This section details on the original issue you should resolve

<issue_title>Feature Request: Dark Mode</issue_title>
<issue_description>Would love to be able to use this excellent resource in low light without burning my retinas. Please consider supporting dark mode!</issue_description>

<agent_instructions>Background information:

  1. This is a hugo static generator based website.
  2. The styles are based on bulma css.

</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@emptymalei Hi @aadityabhatia Thanks for the issue.

This is a great idea. Will definitely do this on the next release.

@emptymalei Hi @aadityabhatia after some experiments, I realized that there is no elegant plugin and use solution for this. So I started developing a completely new theme using modern tech stack. @emptymalei Update:

I am very slow but making progress.

I am testing a new template: https://frameworks.leima.is/frameworks/

This is how it looks like:

Screenshot 2024-01-17 at 20 03 24

This is the source code:
https://github.com/emptymalei/frameworks

Once this reaches a stage that is stable enough, I will replace the current template with it.

I would be very happy to hear feedbacks on this current draft.</comment_new>


💡 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.

@netlify
Copy link
Copy Markdown

netlify Bot commented Dec 22, 2025

Deploy Preview for kausalflow-tools ready!

Name Link
🔨 Latest commit 5622405
🔍 Latest deploy log https://app.netlify.com/projects/kausalflow-tools/deploys/6948d385561fc40008144b6f
😎 Deploy Preview https://deploy-preview-136--kausalflow-tools.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copilot AI and others added 4 commits December 22, 2025 05:07
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
Copilot AI requested a review from emptymalei December 22, 2025 05:14
@emptymalei emptymalei marked this pull request as ready for review March 18, 2026 15:28
Copilot AI review requested due to automatic review settings March 18, 2026 15:28
@emptymalei emptymalei marked this pull request as draft March 18, 2026 15:28
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 localStorage preference.
  • Adds JS helpers to toggle theme, persist preference, and update the toggle icon.
  • Adds a navbar toggle control (moon/sun icon) gated by theme_variant configuration.

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);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Dark Mode

3 participants