From 69917e234cc53d48e3b987a83cdc07db61f60b90 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Sun, 17 Oct 2021 14:51:00 +0200 Subject: [PATCH 1/4] Remember chosen theme in localStorage This way, the selected theme is kept when changing pages, and for subsequent visits. To prevent flickering, we set the selected theme in a blocking script directly on load. To speed things up further, we now use a `data-theme` attribute instead of classes on the body tag, this way we don't need to wait until the body element is loaded. --- blog/sass/css/edition-2/main.scss | 12 +++--- blog/static/js/edition-2/main.js | 64 +++++++++++++++--------------- blog/templates/edition-2/base.html | 7 ++++ 3 files changed, 44 insertions(+), 39 deletions(-) diff --git a/blog/sass/css/edition-2/main.scss b/blog/sass/css/edition-2/main.scss index c8ca740f..03633ae8 100644 --- a/blog/sass/css/edition-2/main.scss +++ b/blog/sass/css/edition-2/main.scss @@ -92,7 +92,7 @@ body { @include set-colors-light(); } -body.dark { +[data-theme="dark"] body { @include set-colors-dark(); } @@ -103,7 +103,7 @@ body.dark { @include set-colors-dark(); } /* Override dark mode with light mode styles if the user decides to swap */ - body.light { + [data-theme="light"] body { @include set-colors-light(); } } @@ -966,7 +966,7 @@ img { .dark-mode-note { display: none; } -body.dark .dark-mode-note { +[data-theme="dark"] .dark-mode-note { display: block; } @media (prefers-color-scheme: dark) { @@ -975,7 +975,7 @@ body.dark .dark-mode-note { display: block; } /* Override dark mode with light mode styles if the user decides to swap */ - body.light .dark-mode-note { + [data-theme="light"] .dark-mode-note { display: none; } } @@ -994,7 +994,7 @@ body.dark .dark-mode-note { @include light-switch-light(); } -body.dark .light-switch { +[data-theme="dark"] .light-switch { @include light-switch-dark(); } @@ -1003,7 +1003,7 @@ body.dark .light-switch { @include light-switch-dark(); } - body.light .light-switch { + [data-theme="light"] .light-switch { @include light-switch-light(); } } diff --git a/blog/static/js/edition-2/main.js b/blog/static/js/edition-2/main.js index 513fcd9d..3a18428f 100644 --- a/blog/static/js/edition-2/main.js +++ b/blog/static/js/edition-2/main.js @@ -1,17 +1,21 @@ -window.onload = function() { - var container = document.querySelector('#toc-aside'); - +window.onload = function () { + let theme = localStorage.getItem("theme"); + if (theme != null) { + set_theme(theme) + } + + let container = document.querySelector('#toc-aside'); if (container != null) { resize_toc(container); toc_scroll_position(container); - window.onscroll = function() { toc_scroll_position(container) }; + window.onscroll = function () { toc_scroll_position(container) }; } } function resize_toc(container) { - var containerHeight = container.clientHeight; + let containerHeight = container.clientHeight; - var resize = function() { + let resize = function () { if (containerHeight > document.documentElement.clientHeight - 100) { container.classList.add('coarse'); } else { @@ -20,8 +24,8 @@ function resize_toc(container) { }; resize(); - var resizeId; - window.onresize = function() { + let resizeId; + window.onresize = function () { clearTimeout(resizeId); resizeId = setTimeout(resize, 300); }; @@ -32,7 +36,6 @@ function toc_scroll_position(container) { // skip computation if ToC is not visible return; } - var items = container.querySelectorAll("li") // remove active class for all items for (item of container.querySelectorAll("li")) { @@ -40,15 +43,15 @@ function toc_scroll_position(container) { } // look for active item - var site_offset = document.documentElement.scrollTop; - var current_toc_item = null; + let site_offset = document.documentElement.scrollTop; + let current_toc_item = null; for (item of container.querySelectorAll("li")) { if (item.offsetParent === null) { // skip items that are not visible continue; } - var anchor = item.firstElementChild.getAttribute("href"); - var heading = document.querySelector(anchor); + let anchor = item.firstElementChild.getAttribute("href"); + let heading = document.querySelector(anchor); if (heading.offsetTop <= (site_offset + document.documentElement.clientHeight / 3)) { current_toc_item = item; } else { @@ -63,25 +66,20 @@ function toc_scroll_position(container) { } function toggle_lights() { - var body = document.querySelector("body"); - var comment_form = document.querySelector("iframe.giscus-frame"); - if (body != null) { - if (body.classList.contains("dark")) { - body.classList.replace("dark", "light"); - if (comment_form != null) { - comment_form.contentWindow.postMessage({ - giscus: { setConfig: { theme: 'light' } } - }, "https://giscus.app") - } - } else { - body.classList.remove("light"); - body.classList.add("dark"); - if (comment_form != null) { - comment_form.contentWindow.postMessage({ - giscus: { setConfig: { theme: 'dark' } } - }, "https://giscus.app") - } - } - console.log(body) + if (document.documentElement.getAttribute("data-theme") === "dark") { + set_theme("light") + } else { + set_theme("dark") } } + +function set_theme(theme) { + let comment_form = document.querySelector("iframe.giscus-frame"); + document.documentElement.setAttribute("data-theme", theme); + if (comment_form != null) { + comment_form.contentWindow.postMessage({ + giscus: { setConfig: { theme: theme } } + }, "https://giscus.app") + } + localStorage.setItem("theme", theme); +} diff --git a/blog/templates/edition-2/base.html b/blog/templates/edition-2/base.html index f7baa22d..80d99688 100644 --- a/blog/templates/edition-2/base.html +++ b/blog/templates/edition-2/base.html @@ -17,6 +17,13 @@ + + {% block title %}{% endblock title %} From 76b6c445e46349bbd786d203de8bb54538a3dc05 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Sun, 17 Oct 2021 15:40:48 +0200 Subject: [PATCH 2/4] Add a switch for going back to system theme --- blog/sass/css/edition-2/main.scss | 58 ++++++++++++++++++++++++++++++ blog/static/js/edition-2/main.js | 29 ++++++++++----- blog/templates/edition-2/base.html | 1 + 3 files changed, 79 insertions(+), 9 deletions(-) diff --git a/blog/sass/css/edition-2/main.scss b/blog/sass/css/edition-2/main.scss index 03633ae8..c5f8ed52 100644 --- a/blog/sass/css/edition-2/main.scss +++ b/blog/sass/css/edition-2/main.scss @@ -983,10 +983,12 @@ img { /* Manual switch between dark and light mode */ @mixin light-switch-light { + // icon: https://icons.getbootstrap.com/icons/moon-fill/ (MIT licensed) background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23004' class='bi bi-moon' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' d='M14.53 10.53a7 7 0 0 1-9.058-9.058A7.003 7.003 0 0 0 8 15a7.002 7.002 0 0 0 6.53-4.47z'/%3E%3C/svg%3E"); } @mixin light-switch-dark { + // icon: https://icons.getbootstrap.com/icons/brightness-high-fill/ (MIT licensed) background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23ff9' class='bi bi-brightness-high-fill' viewBox='0 0 16 16'%3E%3Cpath d='M12 8a4 4 0 1 1-8 0 4 4 0 0 1 8 0zM8 0a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-1 0v-2A.5.5 0 0 1 8 0zm0 13a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-1 0v-2A.5.5 0 0 1 8 13zm8-5a.5.5 0 0 1-.5.5h-2a.5.5 0 0 1 0-1h2a.5.5 0 0 1 .5.5zM3 8a.5.5 0 0 1-.5.5h-2a.5.5 0 0 1 0-1h2A.5.5 0 0 1 3 8zm10.657-5.657a.5.5 0 0 1 0 .707l-1.414 1.415a.5.5 0 1 1-.707-.708l1.414-1.414a.5.5 0 0 1 .707 0zm-9.193 9.193a.5.5 0 0 1 0 .707L3.05 13.657a.5.5 0 0 1-.707-.707l1.414-1.414a.5.5 0 0 1 .707 0zm9.193 2.121a.5.5 0 0 1-.707 0l-1.414-1.414a.5.5 0 0 1 .707-.707l1.414 1.414a.5.5 0 0 1 0 .707zM4.464 4.465a.5.5 0 0 1-.707 0L2.343 3.05a.5.5 0 1 1 .707-.707l1.414 1.414a.5.5 0 0 1 0 .708z'/%3E%3C/svg%3E"); } @@ -1024,3 +1026,59 @@ img { transition: 200ms ease-out; opacity: 1; } + +/* Clear theme override and go back to system theme */ + +@mixin light-switch-reset-light { + // icon: https://icons.getbootstrap.com/icons/x-circle-fill/ (MIT licensed) + background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23666' class='bi bi-x-circle' viewBox='0 0 16 16'%3E%3Cpath d='M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z'/%3E%3Cpath d='M4.646 4.646a.5.5 0 0 1 .708 0L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.5.5 0 0 1 0-.708z'/%3E%3C/svg%3E"); +} + +@mixin light-switch-reset-dark { + // icon: https://icons.getbootstrap.com/icons/x-circle-fill/ (MIT licensed) + background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23999' class='bi bi-x-circle' viewBox='0 0 16 16'%3E%3Cpath d='M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z'/%3E%3Cpath d='M4.646 4.646a.5.5 0 0 1 .708 0L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.5.5 0 0 1 0-.708z'/%3E%3C/svg%3E"); +} + +.light-switch-reset { + @include light-switch-reset-light(); +} + +.light-switch-reset { + display: none; +} + +[data-theme="light"] .light-switch-reset { + display: block; +} + +[data-theme="dark"] .light-switch-reset { + @include light-switch-reset-dark(); + display: block; +} + +@media (prefers-color-scheme: dark) { + .light-switch-reset { + @include light-switch-reset-dark(); + } + + [data-theme="light"] .light-switch-reset { + @include light-switch-reset-light(); + } +} + +.light-switch-reset { + position: fixed; + left: 5rem; + bottom: 1.5rem; + background-repeat: no-repeat; + width: 2rem; + height: 2rem; + cursor: pointer; + opacity: 0.6; +} + +.light-switch-reset:hover { + transform: scale(1.1); + transition: 200ms ease-out; + opacity: 1; +} diff --git a/blog/static/js/edition-2/main.js b/blog/static/js/edition-2/main.js index 3a18428f..059bafc8 100644 --- a/blog/static/js/edition-2/main.js +++ b/blog/static/js/edition-2/main.js @@ -3,7 +3,7 @@ window.onload = function () { if (theme != null) { set_theme(theme) } - + let container = document.querySelector('#toc-aside'); if (container != null) { resize_toc(container); @@ -74,12 +74,23 @@ function toggle_lights() { } function set_theme(theme) { - let comment_form = document.querySelector("iframe.giscus-frame"); - document.documentElement.setAttribute("data-theme", theme); - if (comment_form != null) { - comment_form.contentWindow.postMessage({ - giscus: { setConfig: { theme: theme } } - }, "https://giscus.app") - } - localStorage.setItem("theme", theme); + document.documentElement.setAttribute("data-theme", theme) + set_giscus_theme(theme) + localStorage.setItem("theme", theme) } + +function clear_theme_override() { + document.documentElement.removeAttribute("data-theme"); + set_giscus_theme("preferred_color_scheme") + localStorage.removeItem("theme") +} + +function set_giscus_theme(theme) { + let comment_form = document.querySelector("iframe.giscus-frame"); + if (comment_form != null) { + comment_form.contentWindow.postMessage({ + giscus: { setConfig: { theme: theme } } + }, "https://giscus.app") + } +} + diff --git a/blog/templates/edition-2/base.html b/blog/templates/edition-2/base.html index 80d99688..da415b22 100644 --- a/blog/templates/edition-2/base.html +++ b/blog/templates/edition-2/base.html @@ -58,6 +58,7 @@
+
From 5ff1aab7b55be014a15e1725bbfb070bfb2ebfa5 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Sun, 17 Oct 2021 16:34:24 +0200 Subject: [PATCH 3/4] Improve layout on mobile and clean up sass code --- blog/sass/css/edition-2/main.scss | 143 ++++++++++++++--------------- blog/templates/edition-2/base.html | 8 +- 2 files changed, 73 insertions(+), 78 deletions(-) diff --git a/blog/sass/css/edition-2/main.scss b/blog/sass/css/edition-2/main.scss index c5f8ed52..d8b8867b 100644 --- a/blog/sass/css/edition-2/main.scss +++ b/blog/sass/css/edition-2/main.scss @@ -982,103 +982,96 @@ img { /* Manual switch between dark and light mode */ -@mixin light-switch-light { - // icon: https://icons.getbootstrap.com/icons/moon-fill/ (MIT licensed) - background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23004' class='bi bi-moon' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' d='M14.53 10.53a7 7 0 0 1-9.058-9.058A7.003 7.003 0 0 0 8 15a7.002 7.002 0 0 0 6.53-4.47z'/%3E%3C/svg%3E"); -} +.theme-switch { + margin-bottom: 1rem; -@mixin light-switch-dark { - // icon: https://icons.getbootstrap.com/icons/brightness-high-fill/ (MIT licensed) - background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23ff9' class='bi bi-brightness-high-fill' viewBox='0 0 16 16'%3E%3Cpath d='M12 8a4 4 0 1 1-8 0 4 4 0 0 1 8 0zM8 0a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-1 0v-2A.5.5 0 0 1 8 0zm0 13a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-1 0v-2A.5.5 0 0 1 8 13zm8-5a.5.5 0 0 1-.5.5h-2a.5.5 0 0 1 0-1h2a.5.5 0 0 1 .5.5zM3 8a.5.5 0 0 1-.5.5h-2a.5.5 0 0 1 0-1h2A.5.5 0 0 1 3 8zm10.657-5.657a.5.5 0 0 1 0 .707l-1.414 1.415a.5.5 0 1 1-.707-.708l1.414-1.414a.5.5 0 0 1 .707 0zm-9.193 9.193a.5.5 0 0 1 0 .707L3.05 13.657a.5.5 0 0 1-.707-.707l1.414-1.414a.5.5 0 0 1 .707 0zm9.193 2.121a.5.5 0 0 1-.707 0l-1.414-1.414a.5.5 0 0 1 .707-.707l1.414 1.414a.5.5 0 0 1 0 .707zM4.464 4.465a.5.5 0 0 1-.707 0L2.343 3.05a.5.5 0 1 1 .707-.707l1.414 1.414a.5.5 0 0 1 0 .708z'/%3E%3C/svg%3E"); + @media (min-width: 80rem) { + position: fixed; + left: 2rem; + bottom: 2rem; + margin-bottom: 0rem; + } } .light-switch { + @mixin light-switch-light { + // icon: https://icons.getbootstrap.com/icons/moon-fill/ (MIT licensed) + background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23004' class='bi bi-moon' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' d='M14.53 10.53a7 7 0 0 1-9.058-9.058A7.003 7.003 0 0 0 8 15a7.002 7.002 0 0 0 6.53-4.47z'/%3E%3C/svg%3E"); + } + + @mixin light-switch-dark { + // icon: https://icons.getbootstrap.com/icons/brightness-high-fill/ (MIT licensed) + background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23ff9' class='bi bi-brightness-high-fill' viewBox='0 0 16 16'%3E%3Cpath d='M12 8a4 4 0 1 1-8 0 4 4 0 0 1 8 0zM8 0a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-1 0v-2A.5.5 0 0 1 8 0zm0 13a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-1 0v-2A.5.5 0 0 1 8 13zm8-5a.5.5 0 0 1-.5.5h-2a.5.5 0 0 1 0-1h2a.5.5 0 0 1 .5.5zM3 8a.5.5 0 0 1-.5.5h-2a.5.5 0 0 1 0-1h2A.5.5 0 0 1 3 8zm10.657-5.657a.5.5 0 0 1 0 .707l-1.414 1.415a.5.5 0 1 1-.707-.708l1.414-1.414a.5.5 0 0 1 .707 0zm-9.193 9.193a.5.5 0 0 1 0 .707L3.05 13.657a.5.5 0 0 1-.707-.707l1.414-1.414a.5.5 0 0 1 .707 0zm9.193 2.121a.5.5 0 0 1-.707 0l-1.414-1.414a.5.5 0 0 1 .707-.707l1.414 1.414a.5.5 0 0 1 0 .707zM4.464 4.465a.5.5 0 0 1-.707 0L2.343 3.05a.5.5 0 1 1 .707-.707l1.414 1.414a.5.5 0 0 1 0 .708z'/%3E%3C/svg%3E"); + } + + display: inline-block; @include light-switch-light(); -} -[data-theme="dark"] .light-switch { - @include light-switch-dark(); -} - -@media (prefers-color-scheme: dark) { - .light-switch { - @include light-switch-dark(); - } - - [data-theme="light"] .light-switch { - @include light-switch-light(); - } -} - -.light-switch { - position: fixed; - left: 2rem; - bottom: 2rem; background-repeat: no-repeat; width: 2rem; height: 2rem; cursor: pointer; opacity: 0.6; -} -.light-switch:hover { - transform: scale(1.3); - transition: 200ms ease-out; - opacity: 1; + &:hover { + transform: scale(1.3); + transition: 200ms ease-out; + opacity: 1; + } + + [data-theme="dark"] & { + @include light-switch-dark(); + } + + @media (prefers-color-scheme: dark) { + @include light-switch-dark(); + + [data-theme="light"] & { + @include light-switch-light(); + } + } } /* Clear theme override and go back to system theme */ -@mixin light-switch-reset-light { - // icon: https://icons.getbootstrap.com/icons/x-circle-fill/ (MIT licensed) - background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23666' class='bi bi-x-circle' viewBox='0 0 16 16'%3E%3Cpath d='M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z'/%3E%3Cpath d='M4.646 4.646a.5.5 0 0 1 .708 0L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.5.5 0 0 1 0-.708z'/%3E%3C/svg%3E"); -} - -@mixin light-switch-reset-dark { - // icon: https://icons.getbootstrap.com/icons/x-circle-fill/ (MIT licensed) - background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23999' class='bi bi-x-circle' viewBox='0 0 16 16'%3E%3Cpath d='M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z'/%3E%3Cpath d='M4.646 4.646a.5.5 0 0 1 .708 0L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.5.5 0 0 1 0-.708z'/%3E%3C/svg%3E"); -} - .light-switch-reset { + @mixin light-switch-reset-light { + // icon: https://icons.getbootstrap.com/icons/x-circle-fill/ (MIT licensed) + background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23666' class='bi bi-x-circle' viewBox='0 0 16 16'%3E%3Cpath d='M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z'/%3E%3Cpath d='M4.646 4.646a.5.5 0 0 1 .708 0L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.5.5 0 0 1 0-.708z'/%3E%3C/svg%3E"); + } + + @mixin light-switch-reset-dark { + // icon: https://icons.getbootstrap.com/icons/x-circle-fill/ (MIT licensed) + background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23999' class='bi bi-x-circle' viewBox='0 0 16 16'%3E%3Cpath d='M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z'/%3E%3Cpath d='M4.646 4.646a.5.5 0 0 1 .708 0L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.5.5 0 0 1 0-.708z'/%3E%3C/svg%3E"); + } + @include light-switch-reset-light(); -} - -.light-switch-reset { - display: none; -} - -[data-theme="light"] .light-switch-reset { - display: block; -} - -[data-theme="dark"] .light-switch-reset { - @include light-switch-reset-dark(); - display: block; -} - -@media (prefers-color-scheme: dark) { - .light-switch-reset { - @include light-switch-reset-dark(); - } - - [data-theme="light"] .light-switch-reset { - @include light-switch-reset-light(); - } -} - -.light-switch-reset { - position: fixed; - left: 5rem; - bottom: 1.5rem; + vertical-align: bottom; + margin-left: 0.5rem; background-repeat: no-repeat; width: 2rem; height: 2rem; cursor: pointer; opacity: 0.6; -} -.light-switch-reset:hover { - transform: scale(1.1); - transition: 200ms ease-out; - opacity: 1; + display: none; + [data-theme="light"] & { + display: inline-block; + } + [data-theme="dark"] & { + @include light-switch-reset-dark(); + display: inline-block; + } + + @media (min-width: 80rem) { + position: fixed; + left: 4.5rem; + bottom: 2rem; + } + + &:hover { + transform: scale(1.1); + transition: 200ms ease-out; + opacity: 1; + } } diff --git a/blog/templates/edition-2/base.html b/blog/templates/edition-2/base.html index da415b22..d2b9f81a 100644 --- a/blog/templates/edition-2/base.html +++ b/blog/templates/edition-2/base.html @@ -41,6 +41,11 @@ +
+
+
+
+
{% block toc_aside %}{% endblock toc_aside %}
{% block main %}{% endblock main %}
@@ -57,9 +62,6 @@
-
-
- From 0fa31a0e153e5bda52cc0ca9569ebfcf207db9da Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Sun, 17 Oct 2021 16:34:59 +0200 Subject: [PATCH 4/4] Fix: don't assume that light mode is active on initial theme switch --- blog/static/js/edition-2/main.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/blog/static/js/edition-2/main.js b/blog/static/js/edition-2/main.js index 059bafc8..1ebee250 100644 --- a/blog/static/js/edition-2/main.js +++ b/blog/static/js/edition-2/main.js @@ -68,8 +68,10 @@ function toc_scroll_position(container) { function toggle_lights() { if (document.documentElement.getAttribute("data-theme") === "dark") { set_theme("light") - } else { + } else if (document.documentElement.getAttribute("data-theme") === "light") { set_theme("dark") + } else { + set_theme(window.matchMedia("(prefers-color-scheme: dark)").matches ? "light" : "dark") } }