Skip to content

Commit 515d108

Browse files
afhtbm
authored andcommitted
Add support for dark mode
1 parent aa30a24 commit 515d108

File tree

4 files changed

+105
-20
lines changed

4 files changed

+105
-20
lines changed

flake.nix

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,14 @@
7070
buildFlags = "doc";
7171

7272
postBuild = ''
73+
# Create print version of ledger manpage
7374
pdfroff -man -dpaper=letter -P-pletter $src/doc/ledger.1 > ledger.1.pdf
75+
# Patch web version of ledger manual to support dark mode
76+
sed -e 's@</style>@&<link rel="stylesheet" type="text/css" href="/stylesheets/doc.css">@' ledger3.html -i
7477
'';
7578

7679
postInstall = ''
80+
# Install print version of ledger manpage
7781
cp ledger.1.pdf $out/share/doc/ledger
7882
'';
7983
};
@@ -95,6 +99,8 @@
9599
runHook preBuild
96100
texi2pdf --batch ledger-mode.texi
97101
makeinfo --force --html --no-split ledger-mode.texi
102+
# Patch web version of ledger mode manual to support dark mode
103+
sed -e 's@</style>@&<link rel="stylesheet" type="text/css" href="/stylesheets/doc.css">@' ledger-mode.html -i
98104
runHook postBuild
99105
'';
100106

source/stylesheets/darkmode.css.scss

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
:root {
2+
--light-color:#121212;
3+
--light-background-color:#fcfcfc;
4+
--light-highlight-code-background-color:#eee;
5+
--light-link-color:#00e;
6+
--light-visited-color:#551a8b;
7+
8+
--dark-color:#fefefe;
9+
--dark-background-color:#212121;
10+
--dark-highlight-code-background-color:#333;
11+
--dark-link-color:#2997ff;
12+
--dark-visited-color:#aa6fdf;
13+
}
14+
15+
@media (prefers-color-scheme: light) {
16+
:root {
17+
--color:var(--light-color);
18+
--background-color:var(--light-background-color);
19+
--highlight-code-background-color:var(--light-highlight-code-background-color);
20+
--link-color:var(--light-link-color);
21+
--visited-color:var(--light-visited-color);
22+
}
23+
}
24+
@media (prefers-color-scheme: dark) {
25+
:root {
26+
--color:var(--dark-color);
27+
--background-color:var(--dark-background-color);
28+
--highlight-code-background-color:var(--dark-highlight-code-background-color);
29+
--link-color:var(--dark-link-color);
30+
--visited-color:var(--dark-visited-color);
31+
}
32+
}
33+
34+
body.light-theme, body.dark-theme {
35+
color:var(--toggled-color);
36+
background:var(--toggled-background-color);
37+
nav ul li a[href="/"] {
38+
color:var(--toggled-color);
39+
}
40+
pre code {
41+
background-color:var(--toggled-highlight-code-background-color);
42+
}
43+
.github-corner svg {
44+
color:var(--toggled-background-color) !important;
45+
fill:var(--toggled-color) !important;
46+
}
47+
:link {
48+
color:var(--toggled-link-color);
49+
}
50+
:visited {
51+
color:var(--toggled-visited-color);
52+
}
53+
}

source/stylesheets/doc.css.scss

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@import url("darkmode.css");
2+
3+
body {
4+
color:var(--color);
5+
background:var(--background-color);
6+
}
7+
8+
:link {
9+
color:var(--link-color);
10+
}
11+
12+
:visited {
13+
color:var(--visited-color);
14+
}
15+

source/stylesheets/site.css.scss

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
@import url("darkmode.css");
2+
13
body {
2-
background-color:white;
3-
color:black;
4+
color:var(--color);
5+
background:var(--background-color);
46
font-family:sans-serif;
57
margin:0;
6-
line-height: 1.2;
8+
line-height:1.2;
79
}
810

911
main {
@@ -18,56 +20,61 @@ header {
1820

1921
li {
2022
display:inline-block;
21-
margin: 0 2em 0 0;
23+
margin:0 2em 0 0;
2224
}
2325

2426
a { text-decoration:none; }
2527
}
2628

27-
nav ul {
28-
padding: 0;
29+
:link {
30+
color:var(--link-color);
31+
}
32+
33+
:visited {
34+
color:var(--visited-color);
2935
}
3036

3137
nav {
3238
display:inline;
3339

3440
ul {
3541
display:inline;
42+
padding:0;
3643
}
3744

3845
li {
3946
white-space:nowrap;
4047

4148
a[href="/"] {
42-
color: black;
49+
color:var(--color);
4350
}
4451
}
4552
li:has(a[href="/"]) {
4653
font-size:50px;
47-
margin-left: 0;
54+
margin-left:0;
4855
}
4956
}
5057

5158
article {
5259
padding:1em;
5360

5461
h1 {
55-
font-size: 2em;
62+
font-size:2em;
5663
}
5764
}
5865

5966
pre, code, tt {
6067
font-family:monospace;
6168
}
6269

63-
pre {
70+
pre.highlight {
6471
margin:0 0 0 1em;
65-
}
66-
pre code {
67-
padding:0.5em;
68-
display:inline-block;
69-
background: #eee;
70-
font-size:small;
72+
code {
73+
padding:0.5em;
74+
display:inline-block;
75+
background:var(--highlight-code-background-color);
76+
font-size:small;
77+
}
7178
}
7279

7380
.large {
@@ -83,13 +90,17 @@ pre code {
8390
}
8491

8592
.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}
93+
.github-corner svg {
94+
color:var(--background-color) !important;
95+
fill:var(--color) !important;
96+
}
8697

87-
@media screen and (max-width: 765px) {
98+
@media screen and (max-width:765px) {
8899
header li {
89-
margin: 1em 2em 0 0;
100+
margin:1em 2em 0 0;
90101
}
91102
nav li:has(a[href="/"]) {
92-
display: block;
93-
margin: 0;
103+
display:block;
104+
margin:0;
94105
}
95106
}

0 commit comments

Comments
 (0)