diff options
author | Martin Fischer <martin@push-f.com> | 2025-08-04 20:51:59 +0200 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2025-08-16 20:52:57 +0200 |
commit | 3cada41922abb83b5a5541e4b5efd3fc1659c483 (patch) | |
tree | 63ee2be103394520d78521b12b1711d4968b0cc1 | |
parent | f5613007297731d12f65ef81e1abacafe1f38cec (diff) |
fix: enable dark theme via CSS
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | assets/css/colors/default.css | 16 | ||||
-rw-r--r-- | layouts/_default/baseof.html | 1 | ||||
-rw-r--r-- | static/js/theme-switch.js | 28 |
4 files changed, 11 insertions, 36 deletions
@@ -2,6 +2,8 @@ Tastefejl is a fork of the [Typo] Hugo theme, with the following changes: +* Replaced the JavaScript theme switching code with a CSS media query. + * Removed [Simple Icons] because I don't want to plaster brands on my website and at one point a 50MB .html file was committed (I filtered the git history to reduce the size of the repository.) diff --git a/assets/css/colors/default.css b/assets/css/colors/default.css index ad820ec..08db276 100644 --- a/assets/css/colors/default.css +++ b/assets/css/colors/default.css @@ -6,10 +6,12 @@ --code-border: rgb(229, 229, 229); } -.dark { - --content-primary: rgb(218, 218, 218); - --content-secondary: rgb(140, 140, 140); - --background: rgb(20, 20, 20); - --code-background: rgb(30, 30, 30); - --code-border: rgb(50, 50, 50); -}
\ No newline at end of file +@media (prefers-color-scheme: dark) { + :root { + --content-primary: rgb(218, 218, 218); + --content-secondary: rgb(140, 140, 140); + --background: rgb(20, 20, 20); + --code-background: rgb(30, 30, 30); + --code-border: rgb(50, 50, 50); + } +} diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index 2decab0..b5c8cc4 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -36,6 +36,5 @@ {{ end }} </body> -<script src="{{ "js/theme-switch.js" | relURL }}"></script> <script defer src="{{ "js/copy-code.js" | relURL }}"></script> </html> diff --git a/static/js/theme-switch.js b/static/js/theme-switch.js deleted file mode 100644 index a617fda..0000000 --- a/static/js/theme-switch.js +++ /dev/null @@ -1,28 +0,0 @@ -function isAuto() { - return document.body.classList.contains("auto"); -} - -function setTheme() { - if (!isAuto()) { - return - } - - document.body.classList.remove("auto"); - let cls = "light"; - if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { - cls = "dark"; - } - - document.body.classList.add(cls); -} - -function invertBody() { - document.body.classList.toggle("dark"); - document.body.classList.toggle("light"); -} - -if (isAuto()) { - window.matchMedia('(prefers-color-scheme: dark)').addListener(invertBody); -} - -setTheme(); |