Skip to content

Commit f23ab5a

Browse files
authored
Use CSS inside noscript when JS is disabled to detect preferred color theme (adityatelange#308)
- Makes auto theme work when JS is disabled - Only applies if the 'theme' configuration parameter is set to 'auto' or is unset.
1 parent 643fdbe commit f23ab5a

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

layouts/partials/header.html

+18-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,24 @@
4444
.top-link {
4545
display: none;
4646
}
47-
47+
{{- if (and (ne .Site.Params.defaultTheme "light") (ne .Site.Params.defaultTheme "dark")) }}
48+
@media (prefers-color-scheme: dark) {
49+
:root {
50+
--theme: #1d1e20;
51+
--entry: #2e2e33;
52+
--primary: rgba(255, 255, 255, 0.84);
53+
--secondary: rgba(255, 255, 255, 0.56);
54+
--tertiary: rgba(255, 255, 255, 0.16);
55+
--content: rgba(255, 255, 255, 0.74);
56+
--hljs-bg: #2e2e33;
57+
--code-bg: #37383e;
58+
--border: #333;
59+
}
60+
.list {
61+
background: var(--theme);
62+
}
63+
}
64+
{{- end }}
4865
</style>
4966
</noscript>
5067
<header class="header">

0 commit comments

Comments
 (0)