From 19f5d7df33b2deaf3bd2efc68bd3d163c93b194f Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Tue, 10 May 2022 22:04:58 -0400 Subject: [PATCH] Implement dark mode without using CSS variables. Instead of using CSS variables, we can just directly change colours with appropriate media queries. Moreover, implement a small postprocessor which consolidates all the dark mode rules together at the end of the stylesheet, which makes it a svery imple matter to also link an alternate stylesheet which is selectable in older browsers. --- Rules | 8 +++ content/style.scss | 8 +-- layouts/default.xsl | 4 +- lib/colourmap.scss | 49 ++++++------- lib/compiledcontent.rb | 25 +++++++ lib/css-darkmode.rb | 158 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 220 insertions(+), 32 deletions(-) create mode 100644 lib/compiledcontent.rb create mode 100644 lib/css-darkmode.rb diff --git a/Rules b/Rules index b8538d8..1aa5907 100644 --- a/Rules +++ b/Rules @@ -217,9 +217,17 @@ compile '/**/*.scss' do filter :css_clean_selectors, \ preserve_comments: true, \ preserve_hacks: true + snapshot :before_darkmode + filter :css_darkmode write @item.identifier.without_ext + '.css' end +compile '/style.scss', rep: :dark do + filter :compiled_content, snapshot: :before_darkmode + filter :css_darkmode, alternate: true + write "/dark.css" +end + compile '/gpg/*' do filter :wkd_export_armor write "/pubring/#{@item.identifier.components.last}.asc" diff --git a/content/style.scss b/content/style.scss index 5f2ef96..fb33f88 100644 --- a/content/style.scss +++ b/content/style.scss @@ -329,7 +329,7 @@ $clickynames: name, date, size; @include usecolours($border-color: foreground); @at-root { @supports (outline-style: auto) { & { @include usecolour(outline, focusring, auto); - border-color: transparent; + border-color: transparent !important; }}} } } @@ -455,14 +455,14 @@ ul.ordered > { } // page-specific dark mode styles -@media (min-width: 35em) { +@media (prefers-color-scheme: dark) and (min-width: 35em) { #page_weblog_responsive_tables { @each $tN in t6 t7 t8 { ##{$tN}>tbody>tr.#{$tN}-split { - @include usecolour_var_(border-bottom, ruledefault); + @include usecolour_dark_(border-bottom, ruledefault); &:nth-of-type(odd) ~ tr:nth-of-type(odd) { - @include usecolour_var_(background-color, tableshade); + @include usecolour_dark_(background-color, tableshade); } } } diff --git a/layouts/default.xsl b/layouts/default.xsl index 837a792..d5be103 100644 --- a/layouts/default.xsl +++ b/layouts/default.xsl @@ -2,7 +2,7 @@