Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions templates/base.html.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,21 @@
</head>
<body>
<script>
var colorSchemeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
function getSystemTheme() {
return colorSchemeMediaQuery.matches ? 'dark' : 'light';
}
function getStoredTheme() {
return localStorage.getItem('theme');
}
function getTheme() {
return getStoredTheme() || getSystemTheme();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

stored theme (if different from system) wins

It always wins?

Copy link
Copy Markdown
Collaborator

@m-aciek m-aciek Jun 7, 2026

Choose a reason for hiding this comment

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

yes, please note we clear it when user changes the theme to the same as system

nothing changes for users that use always light theme or always dark

things change for those who use auto aka follow-the-sun

if you set to light during night, you'll have light in stored, therefore always light

but if you set to dark during night, the theme will start to be auto/follow-the-sun as your OS does (technically we will clear the stored theme, and then || getSystemTheme() will be used)

}
function applyTheme(t) {
document.documentElement.setAttribute('data-bs-theme', t);
document.documentElement.classList.toggle('dark', t === 'dark');
}
applyTheme(localStorage.getItem('theme') || (matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'));
applyTheme(getTheme());
</script>
<header>
<nav class="navbar navbar-expand-md fixed-top">
Expand Down Expand Up @@ -136,8 +146,17 @@
window.addEventListener('resize', padnavbar);
document.getElementById('theme-toggle').addEventListener('click', function() {
var next = document.documentElement.getAttribute('data-bs-theme') === 'dark' ? 'light' : 'dark';
localStorage.setItem('theme', next);
applyTheme(next);
if (next === getSystemTheme()) {
localStorage.removeItem('theme');
Comment thread
m-aciek marked this conversation as resolved.
} else {
localStorage.setItem('theme', next);
}
applyTheme(getTheme());
});
colorSchemeMediaQuery.addEventListener('change', function() {
if (!getStoredTheme()) {
applyTheme(getTheme());
}
});
</script>
<script src="https://code.jquery.com/jquery-4.0.0.slim.min.js" integrity="sha256-8DGpv13HIm+5iDNWw1XqxgFB4mj+yOKFNb+tHBZOowc=" crossorigin="anonymous">
Expand Down
Loading