From f4e041224499dd376847b69548d2417be0c0ef47 Mon Sep 17 00:00:00 2001 From: SandaruKasa Date: Tue, 4 Jul 2023 19:31:33 +0300 Subject: [PATCH] Cull excessive JS/CSS for `{dark,light}-without-swticher` styles --- assets/css/main.css | 18 ++++++++++++++---- layouts/partials/head.html | 7 +++++++ layouts/partials/theme-switcher.html | 6 ++++-- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/assets/css/main.css b/assets/css/main.css index 57bbce5..071e2a8 100644 --- a/assets/css/main.css +++ b/assets/css/main.css @@ -1,24 +1,34 @@ {{ $light := resources.Get "css/light.css" }} {{ $dark := resources.Get "css/dark.css" }} -{{ $light.Content }} +{{ $style := "light-without-switcher" }} +{{ if and (isset site.Params "style") (ne site.Params.style "") }} + {{ $style = site.Params.style | lower }} +{{ end }} -{{ if eq site.Params.style "dark-without-switcher" }} +{{ if eq $style "dark-without-switcher" }} :root { {{ $dark.Content }} } -{{ else if eq site.Params.style "auto-without-switcher" }} + +{{ else }} + +{{ $light.Content }} + +{{ if eq $style "auto-without-switcher" }} @media (prefers-color-scheme: dark) { :root { {{ $dark.Content }} } } -{{else }} +{{ else if ne $style "light-without-switcher" }} [data-theme="dark"] { {{ $dark.Content }} } {{ end }} +{{ end }} + /* Basic */ html { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; diff --git a/layouts/partials/head.html b/layouts/partials/head.html index b8da3ac..24104fd 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -21,6 +21,12 @@ {{ partial "favicons.html" . }} +{{ $style := "light-without-switcher" }} +{{ if and (isset site.Params "style") (ne site.Params.style "") }} + {{ $style = site.Params.style | lower }} +{{ end }} + +{{ if not (in (slice "light-without-switcher" "dark-without-switcher") $style) }} +{{end}} {{ partial "resource.html" (dict "context" . "type" "css" "filename" "css/main.css") }} diff --git a/layouts/partials/theme-switcher.html b/layouts/partials/theme-switcher.html index dd24831..5208ea9 100644 --- a/layouts/partials/theme-switcher.html +++ b/layouts/partials/theme-switcher.html @@ -3,7 +3,8 @@ {{ $style = site.Params.style | lower }} {{ end }} -{{ if not (in (slice "light-without-switcher" "dark-without-switcher" "auto-without-switcher") $style) }} +{{ if not (in (slice "light-without-switcher" "dark-without-switcher") $style) }} +{{ if ne "auto-without-switcher" $style }} @@ -84,4 +85,5 @@ function showContent() { document.body.style.visibility = 'visible'; document.body.style.opacity = 1; } - \ No newline at end of file + +{{ end }}