aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/templates/-base.html.tmpl
diff options
context:
space:
mode:
Diffstat (limited to 'src/templates/-base.html.tmpl')
-rw-r--r--src/templates/-base.html.tmpl45
1 files changed, 28 insertions, 17 deletions
diff --git a/src/templates/-base.html.tmpl b/src/templates/-base.html.tmpl
index 42ec216..2e78a7c 100644
--- a/src/templates/-base.html.tmpl
+++ b/src/templates/-base.html.tmpl
@@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
{{ if .Debugp }}
- <link href="/style.css" type="text/css" rel="stylesheet">
+ <link href="/style-2.css" type="text/css" rel="stylesheet">
{{ else }}
<link href="/style.min.css" type="text/css" rel="stylesheet">
{{ end }}
@@ -14,30 +14,41 @@
const $$ = q => document.querySelectorAll(q);
(() => {
- const validate = theme =>
- ["light", "dark"].includes(theme) ? theme : "light";
- const toggle = theme =>
- theme == "light" ? "dark" : "light";
+ document.addEventListener("DOMContentLoaded", _ => {
+ const root = $("html");
+ const icons = {
+ light: $("#nav-icon-theme-light"),
+ dark: $("#nav-icon-theme-dark"),
+ };
- const setTheme = theme => {
- localStorage.setItem("theme", theme);
- $("html").setAttribute("data-theme", theme);
- $(`#nav-icon-theme-${theme}`).style.display = "";
- $(`#nav-icon-theme-${toggle(theme)}`).style.display = "none";
- };
+ const toggle = theme =>
+ theme === "light" ? "dark" : "light"
- document.addEventListener("DOMContentLoaded", _ => {
- $("#theme-button").onclick = () =>
- setTheme(toggle(validate(localStorage.getItem("theme"))));
- setTheme(validate(localStorage.getItem("theme")));
+ const setTheme = theme => {
+ localStorage.setItem("theme", theme);
+ root.setAttribute("data-theme", theme);
+ icons[theme].style.display = "";
+ icons[toggle(theme)].style.display = "none";
+ };
+
+ /* Double toggle to handle invalid theme */
+ setTheme(toggle(toggle(localStorage.getItem("theme"))));
+ $("#theme-button").onclick = () => {
+ const theme = toggle(localStorage.getItem("theme"));
+ if (document.startViewTransition)
+ document.startViewTransition(() => setTheme(theme));
+ else
+ setTheme(theme);
+ };
});
})();
</script>
- {{ includeIfExists "header" . }}
+
+ {{ template "header" . }}
</head>
<body>
{{ template "content" . }}
- <footer>
+ <footer class="container">
<p>
<small>
{{ .Get "Found a mistake or want to contribute missing information?" }}