Skip to content

Commit 797e368

Browse files
committed
Allow toggling of dark scheme with a body class.
1 parent c467025 commit 797e368

2 files changed

Lines changed: 140 additions & 120 deletions

File tree

assets/css/_dark/dark-main.scss

Lines changed: 60 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -6,55 +6,65 @@
66
* MIT Licensed
77
*/
88

9+
@mixin darkScheme() {
10+
/* framework */
11+
--main-wrapper-bg: rgb(27, 27, 30);
12+
--topbar-wrapper-bg: rgb(39, 40, 43);
13+
--search-wrapper-bg: rgb(34, 34, 39);
14+
--search-icon: rgb(100, 102, 105);
15+
--input-focus-border: rgb(112, 114, 115);
16+
--footer-bg: rgb(31, 30, 30);
17+
--footer-border: rgb(44, 45, 45);
18+
--mask-bg: rgb(68, 69, 70);
19+
20+
/* sidebar */
21+
--nav-cursor: rgb(183, 182, 182);
22+
--sidebar-bg: radial-gradient(circle, #242424 0%, #1d1f27 100%);
23+
24+
/* common color */
25+
--text-color: rgb(175, 176, 177);
26+
--text-muted-color: rgb(107, 116, 124);
27+
--link-color: #3db5c2;
28+
--link-underline-color: #3db5c2;
29+
--main-border: rgb(63, 65, 68);
30+
--button-bg: rgb(39, 40, 33);
31+
--blockquote-border: rgb(66, 66, 66);
32+
--blockquote-text: rgb(117, 117, 117);
33+
34+
--card-bg: rgb(39, 40, 33);
35+
--card-header-bg: rgb(51, 50, 50);
36+
--relate-post-title: rgb(164, 175, 181);
37+
38+
/* Home page */
39+
--btn-active-bg: #1c345e;
40+
--btn-active-border-color: #8ab4f8;
41+
42+
/* posts */
43+
--toc-highlight: rgb(116, 178, 243);
44+
--tag-bg: rgb(41, 40, 40);
45+
--tag-hover: rgb(43, 56, 62);
46+
--tb-odd-bg: rgba(52, 53, 42, 0.52); /* odd rows of the posts' table */
47+
--tb-even-bg: rgb(31, 31, 34); /* even rows of the posts' table */
48+
49+
/* tags */
50+
--tag-border: rgb(59, 79, 88);
51+
--tag-shadow: rgb(32, 33, 33);
52+
53+
/* categories */
54+
--categories-hover-bg: rgb(73, 75, 76);
55+
56+
/* archives */
57+
--timeline-node-bg: rgb(150, 152, 156);
58+
}
59+
960
@media (prefers-color-scheme: dark) {
10-
html {
11-
/* framework */
12-
--main-wrapper-bg: rgb(27, 27, 30);
13-
--topbar-wrapper-bg: rgb(39, 40, 43);
14-
--search-wrapper-bg: rgb(34, 34, 39);
15-
--search-icon: rgb(100, 102, 105);
16-
--input-focus-border: rgb(112, 114, 115);
17-
--footer-bg: rgb(31, 30, 30);
18-
--footer-border: rgb(44, 45, 45);
19-
--mask-bg: rgb(68, 69, 70);
20-
21-
/* sidebar */
22-
--nav-cursor: rgb(183, 182, 182);
23-
--sidebar-bg: radial-gradient(circle, #242424 0%, #1d1f27 100%);
24-
25-
/* common color */
26-
--text-color: rgb(175, 176, 177);
27-
--text-muted-color: rgb(107, 116, 124);
28-
--link-color: rgb(138, 180, 248);
29-
--link-underline-color: rgb(99, 131, 182);
30-
--main-border: rgb(63, 65, 68);
31-
--button-bg: rgb(39, 40, 33);
32-
--blockquote-border: rgb(66, 66, 66);
33-
--blockquote-text: rgb(117, 117, 117);
34-
35-
--card-bg: rgb(39, 40, 33);
36-
--card-header-bg: rgb(51, 50, 50);
37-
--relate-post-title: rgb(164, 175, 181);
38-
39-
/* Home page */
40-
--btn-active-bg: #1c345e;
41-
--btn-active-border-color: #8ab4f8;
42-
43-
/* posts */
44-
--toc-highlight: rgb(116, 178, 243);
45-
--tag-bg: rgb(41, 40, 40);
46-
--tag-hover: rgb(43, 56, 62);
47-
--tb-odd-bg: rgba(52, 53, 42, 0.52); /* odd rows of the posts' table */
48-
--tb-even-bg: rgb(31, 31, 34); /* even rows of the posts' table */
49-
50-
/* tags */
51-
--tag-border: rgb(59, 79, 88);
52-
--tag-shadow: rgb(32, 33, 33);
53-
54-
/* categories */
55-
--categories-hover-bg: rgb(73, 75, 76);
56-
57-
/* archives */
58-
--timeline-node-bg: rgb(150, 152, 156);
61+
body:not(.color-scheme-light) {
62+
@include darkScheme();
63+
}
64+
}
65+
66+
@media not (prefers-color-scheme: dark) {
67+
body.color-scheme-dark {
68+
@include darkScheme();
5969
}
60-
}
70+
}

assets/css/_dark/dark-syntax.scss

Lines changed: 80 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -6,77 +6,76 @@
66
* MIT Licensed
77
*/
88

9-
@media (prefers-color-scheme: dark) {
10-
html {
11-
/* syntax highlight colors from https://raw.githubusercontent.com/jwarby/pygments-css/master/monokai.css */
12-
--highlight-pre-bg: #272822;
13-
--highlight-hll-bg: #272822;
14-
--highlight-c: #75715e; /* Comment */
15-
--highlight-err: #960050; /* Error */
16-
--highlight-err-bg: #1e0010; /* Error background */
17-
--highlight-k: #66d9ef; /* Keyword */
18-
--highlight-l: #ae81ff; /* Literal */
19-
--highlight-n: #f8f8f2; /* Name */
20-
--highlight-o: #f92672; /* Operator */
21-
--highlight-p: #f8f8f2; /* Punctuation */
22-
--highlight-cm: #75715e; /* Comment.Multiline */
23-
--highlight-cp: #75715e; /* Comment.Preproc */
24-
--highlight-c1: #75715e; /* Comment.Single */
25-
--highlight-cs: #75715e; /* Comment.Special */
26-
--highlight-kc: #66d9ef; /* Keyword.Constant */
27-
--highlight-kd: #66d9ef; /* Keyword.Declaration */
28-
--highlight-kn: #f92672; /* Keyword.Namespace */
29-
--highlight-kp: #66d9ef; /* Keyword.Pseudo */
30-
--highlight-kr: #66d9ef; /* Keyword.Reserved */
31-
--highlight-kt: #66d9ef; /* Keyword.Type */
32-
--highlight-ld: #e6db74; /* Literal.Date */
33-
--highlight-m: #ae81ff; /* Literal.Number */
34-
--highlight-s: #e6db74; /* Literal.String */
35-
--highlight-na: #a6e22e; /* Name.Attribute */
36-
--highlight-nb: #f8f8f2; /* Name.Builtin */
37-
--highlight-nc: #a6e22e; /* Name.Class */
38-
--highlight-no: #66d9ef; /* Name.Constant */
39-
--highlight-nd: #a6e22e; /* Name.Decorator */
40-
--highlight-ni: #f8f8f2; /* Name.Entity */
41-
--highlight-ne: #a6e22e; /* Name.Exception */
42-
--highlight-nf: #a6e22e; /* Name.Function */
43-
--highlight-nl: #f8f8f2; /* Name.Label */
44-
--highlight-nn: #f8f8f2; /* Name.Namespace */
45-
--highlight-nx: #a6e22e; /* Name.Other */
46-
--highlight-py: #f8f8f2; /* Name.Property */
47-
--highlight-nt: #f92672; /* Name.Tag */
48-
--highlight-nv: #f8f8f2; /* Name.Variable */
49-
--highlight-ow: #f92672; /* Operator.Word */
50-
--highlight-w: #f8f8f2; /* Text.Whitespace */
51-
--highlight-mf: #ae81ff; /* Literal.Number.Float */
52-
--highlight-mh: #ae81ff; /* Literal.Number.Hex */
53-
--highlight-mi: #ae81ff; /* Literal.Number.Integer */
54-
--highlight-mo: #ae81ff; /* Literal.Number.Oct */
55-
--highlight-sb: #e6db74; /* Literal.String.Backtick */
56-
--highlight-sc: #e6db74; /* Literal.String.Char */
57-
--highlight-sd: #e6db74; /* Literal.String.Doc */
58-
--highlight-s2: #e6db74; /* Literal.String.Double */
59-
--highlight-se: #ae81ff; /* Literal.String.Escape */
60-
--highlight-sh: #e6db74; /* Literal.String.Heredoc */
61-
--highlight-si: #e6db74; /* Literal.String.Interpol */
62-
--highlight-sx: #e6db74; /* Literal.String.Other */
63-
--highlight-sr: #e6db74; /* Literal.String.Regex */
64-
--highlight-s1: #e6db74; /* Literal.String.Single */
65-
--highlight-ss: #e6db74; /* Literal.String.Symbol */
66-
--highlight-bp: #f8f8f2; /* Name.Builtin.Pseudo */
67-
--highlight-vc: #f8f8f2; /* Name.Variable.Class */
68-
--highlight-vg: #f8f8f2; /* Name.Variable.Global */
69-
--highlight-vi: #f8f8f2; /* Name.Variable.Instance */
70-
--highlight-il: #ae81ff; /* Literal.Number.Integer.Long */
9+
@mixin darkSchemeHighlight() {
7110

72-
// --highlight-gh: none; /* Generic Heading & Diff Header */
73-
--highlight-gu: #75715e; /* Generic.Subheading & Diff Unified/Comment? */
74-
--highlight-gd: #f92672; /* Generic.Deleted & Diff Deleted */
11+
/* syntax highlight colors from https://raw.githubusercontent.com/jwarby/pygments-css/master/monokai.css */
12+
--highlight-pre-bg: #272822;
13+
--highlight-hll-bg: #272822;
14+
--highlight-c: #75715e; /* Comment */
15+
--highlight-err: #960050; /* Error */
16+
--highlight-err-bg: #1e0010; /* Error background */
17+
--highlight-k: #66d9ef; /* Keyword */
18+
--highlight-l: #ae81ff; /* Literal */
19+
--highlight-n: #f8f8f2; /* Name */
20+
--highlight-o: #f92672; /* Operator */
21+
--highlight-p: #f8f8f2; /* Punctuation */
22+
--highlight-cm: #75715e; /* Comment.Multiline */
23+
--highlight-cp: #75715e; /* Comment.Preproc */
24+
--highlight-c1: #75715e; /* Comment.Single */
25+
--highlight-cs: #75715e; /* Comment.Special */
26+
--highlight-kc: #66d9ef; /* Keyword.Constant */
27+
--highlight-kd: #66d9ef; /* Keyword.Declaration */
28+
--highlight-kn: #f92672; /* Keyword.Namespace */
29+
--highlight-kp: #66d9ef; /* Keyword.Pseudo */
30+
--highlight-kr: #66d9ef; /* Keyword.Reserved */
31+
--highlight-kt: #66d9ef; /* Keyword.Type */
32+
--highlight-ld: #e6db74; /* Literal.Date */
33+
--highlight-m: #ae81ff; /* Literal.Number */
34+
--highlight-s: #e6db74; /* Literal.String */
35+
--highlight-na: #a6e22e; /* Name.Attribute */
36+
--highlight-nb: #f8f8f2; /* Name.Builtin */
37+
--highlight-nc: #a6e22e; /* Name.Class */
38+
--highlight-no: #66d9ef; /* Name.Constant */
39+
--highlight-nd: #a6e22e; /* Name.Decorator */
40+
--highlight-ni: #f8f8f2; /* Name.Entity */
41+
--highlight-ne: #a6e22e; /* Name.Exception */
42+
--highlight-nf: #a6e22e; /* Name.Function */
43+
--highlight-nl: #f8f8f2; /* Name.Label */
44+
--highlight-nn: #f8f8f2; /* Name.Namespace */
45+
--highlight-nx: #a6e22e; /* Name.Other */
46+
--highlight-py: #f8f8f2; /* Name.Property */
47+
--highlight-nt: #f92672; /* Name.Tag */
48+
--highlight-nv: #f8f8f2; /* Name.Variable */
49+
--highlight-ow: #f92672; /* Operator.Word */
50+
--highlight-w: #f8f8f2; /* Text.Whitespace */
51+
--highlight-mf: #ae81ff; /* Literal.Number.Float */
52+
--highlight-mh: #ae81ff; /* Literal.Number.Hex */
53+
--highlight-mi: #ae81ff; /* Literal.Number.Integer */
54+
--highlight-mo: #ae81ff; /* Literal.Number.Oct */
55+
--highlight-sb: #e6db74; /* Literal.String.Backtick */
56+
--highlight-sc: #e6db74; /* Literal.String.Char */
57+
--highlight-sd: #e6db74; /* Literal.String.Doc */
58+
--highlight-s2: #e6db74; /* Literal.String.Double */
59+
--highlight-se: #ae81ff; /* Literal.String.Escape */
60+
--highlight-sh: #e6db74; /* Literal.String.Heredoc */
61+
--highlight-si: #e6db74; /* Literal.String.Interpol */
62+
--highlight-sx: #e6db74; /* Literal.String.Other */
63+
--highlight-sr: #e6db74; /* Literal.String.Regex */
64+
--highlight-s1: #e6db74; /* Literal.String.Single */
65+
--highlight-ss: #e6db74; /* Literal.String.Symbol */
66+
--highlight-bp: #f8f8f2; /* Name.Builtin.Pseudo */
67+
--highlight-vc: #f8f8f2; /* Name.Variable.Class */
68+
--highlight-vg: #f8f8f2; /* Name.Variable.Global */
69+
--highlight-vi: #f8f8f2; /* Name.Variable.Instance */
70+
--highlight-il: #ae81ff; /* Literal.Number.Integer.Long */
7571

76-
/* My styles */
77-
--highlight-lineno: #6c6c6d;
78-
--highlight-lineno-border: #3c4042;
79-
}
72+
// --highlight-gh: none; /* Generic Heading & Diff Header */
73+
--highlight-gu: #75715e; /* Generic.Subheading & Diff Unified/Comment? */
74+
--highlight-gd: #f92672; /* Generic.Deleted & Diff Deleted */
75+
76+
/* My styles */
77+
--highlight-lineno: #6c6c6d;
78+
--highlight-lineno-border: #3c4042;
8079

8180
pre {
8281
color: #818c96; /* override Bootstrap */
@@ -85,5 +84,16 @@
8584
kbd {
8685
background-color: black;
8786
}
87+
}
8888

89-
}
89+
@media (prefers-color-scheme: dark) {
90+
body:not(.color-scheme-light) {
91+
@include darkSchemeHighlight();
92+
}
93+
}
94+
95+
@media not (prefers-color-scheme: dark) {
96+
body.color-scheme-dark {
97+
@include darkSchemeHighlight();
98+
}
99+
}

0 commit comments

Comments
 (0)