Skip to content

Commit 032d7e8

Browse files
committed
templates: Apply saved theme in base template
Read the saved theme from localStorage on page load and set the data-theme attribute early to avoid a flash of unstyled content. Signed-off-by: Andrea Cervesato <andrea.cervesato@mailbox.org> Assisted-by: Gemini 3.8 Flash
1 parent 3e9fd91 commit 032d7e8

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

‎templates/base.html‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
<!DOCTYPE html>
33
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
44
<head>
5+
<script>
6+
(function() {
7+
try {
8+
var theme = localStorage.getItem('pw_theme');
9+
if (theme === 'dark') {
10+
document.documentElement.setAttribute('data-theme', 'dark');
11+
}
12+
} catch (e) {}
13+
})();
14+
</script>
515
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
616
<title>{% block title %}Patchwork{% endblock %} - Patchwork</title>
717
<link rel="stylesheet" type="text/css" href="{% static "css/bootstrap.min.css" %}"/>

0 commit comments

Comments
 (0)