From 22524617427ae7aecda3eb226a254642f54ae13c Mon Sep 17 00:00:00 2001 From: Hanwen Guo Date: Wed, 20 Sep 2023 21:01:30 +0800 Subject: [PATCH] css(dark mode): fix #13, allow color palettes --- assets/css/main.scss | 45 ++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/assets/css/main.scss b/assets/css/main.scss index ad50f74..3974b1c 100644 --- a/assets/css/main.scss +++ b/assets/css/main.scss @@ -1,30 +1,50 @@ // -------------- THEME SWITCHER -------------- // -@mixin dark-appearance { - filter: invert(1); - img { - filter: invert(1); +@mixin theme($--bg-color, $--primary-text-color, $--secondary-text-color, $--link-color, $--visited-link-color) { + background-color: $--bg-color; - &.ioda { filter: invert(0); } + color: $--primary-text-color; + + a { + color: $--link-color; + text-decoration: none; + + &:visited { color: $--visited-link-color; } + &:hover { text-decoration: underline; } } + + code:not(pre > code) { + background-color: $--primary-text-color; + color: $--bg-color; + } + + figcaption { color: $--secondary-text-color; } +} + +@mixin dark-appearance { + @include theme(#212121, #fafafa, #eeeeee, #0071bc, #a359e9); +} + +@mixin light-appearance { + @include theme(#ffffff, #212121, #666666, #1e70bf, #921292); } body[a="dark"] { @include dark-appearance; } +body[a="light"] { @include light-appearance; } @media (prefers-color-scheme: dark) { body[a="auto"] { @include dark-appearance; } } -// -------------------------------------------- // -// bg color is also needed in html in order to -// block body's background propagation -// see: https://stackoverflow.com/a/61265706 -html, body { background: white; } +@media (prefers-color-scheme: light) { + body[a="auto"] { @include light-appearance; } +} + +// -------------------------------------------- // html { height: 100%; } body { - color: black; font-family: monospace; font-size: 16px; line-height: 1.4; @@ -79,9 +99,6 @@ table, th, td { } code:not(pre > code) { - color: white; - background: black; - font-size: 80%; padding: 0.1em 0.2em; font-size: 90%; }