Skip to content

Commit 786c944

Browse files
committed
Use CSS instead of JS to detect preferred color theme
Only applies if the user has disabled JS and the 'theme' configuration parameter is set to 'auto' or is unset.
1 parent e76154d commit 786c944

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

layouts/partials/header.html

Lines changed: 18 additions & 1 deletion
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)