Skip to content

Commit

Permalink
Merge pull request #356 from freezingsaddles/no-dark-mode-flash
Browse files Browse the repository at this point in the history
Store dark mode in a cookie to avoid always starting in light mode
  • Loading branch information
merlinorg authored Dec 31, 2024
2 parents f6872c6 + 459295b commit 18b4fbf
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion freezing/web/templates/base.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<html lang="en" data-bs-theme="{{ request.cookies.get('theme', 'light') }}">
<head>
<title>
{% block title %}
Expand Down Expand Up @@ -557,6 +557,10 @@
"dark" :
"light";
document.querySelector("html").setAttribute("data-bs-theme", colorMode);
// Persist the theme to avoid light-mode always flashing in first
const date = new Date();
date.setDate(date.getDate() + 30);
document.cookie = "theme=" + colorMode + "; expires=" + date.toUTCString() + "; path=/";
}

// Set theme on load
Expand Down

0 comments on commit 18b4fbf

Please sign in to comment.