Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions assets/css/common/header.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ button#theme-toggle {
margin: auto 4px;
}

body.dark #moon {
vertical-align: middle;
[data-theme="dark"] #moon {
display: none;
}

body:not(.dark) #sun {
[data-theme="light"] #sun {
display: none;
}

Expand Down
2 changes: 1 addition & 1 deletion assets/css/common/post-single.css
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@
padding: 0.4em;
}

.dark .toc {
[data-theme="dark"] .toc {
background: var(--entry);
}

Expand Down
6 changes: 4 additions & 2 deletions assets/css/core/theme-vars.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
--code-block-bg: rgb(28, 29, 33);
--code-bg: rgb(245, 245, 245);
--border: rgb(238, 238, 238);
color-scheme: light;
}

.dark {
:root[data-theme="dark"] {
--theme: rgb(29, 30, 32);
--entry: rgb(46, 46, 51);
--primary: rgb(218, 218, 219);
Expand All @@ -27,12 +28,13 @@
--code-block-bg: rgb(46, 46, 51);
--code-bg: rgb(55, 56, 62);
--border: rgb(51, 51, 51);
color-scheme: dark;
}

.list {
background: var(--code-bg);
}

.dark.list {
[data-theme="dark"] .list {
background: var(--theme);
}
6 changes: 1 addition & 5 deletions assets/css/includes/scroll-bar.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@
background: 0 0;
}

.list:not(.dark)::-webkit-scrollbar-track {
background: var(--code-bg);
}

::-webkit-scrollbar-thumb {
background: var(--tertiary);
border: 5px solid var(--theme);
border-radius: var(--radius);
}

.list:not(.dark)::-webkit-scrollbar-thumb {
[data-theme="light"] .list::-webkit-scrollbar-thumb {
border: 5px solid var(--code-bg);
}

Expand Down
7 changes: 4 additions & 3 deletions layouts/partials/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,12 @@
{{- if (not site.Params.disableThemeToggle) }}
<script>
document.getElementById("theme-toggle").addEventListener("click", () => {
if (document.body.className.includes("dark")) {
document.body.classList.remove('dark');
const html = document.querySelector("html");
if (html.dataset.theme === "dark") {
html.dataset.theme = 'light';
localStorage.setItem("pref-theme", 'light');
} else {
document.body.classList.add('dark');
html.dataset.theme = 'dark';
localStorage.setItem("pref-theme", 'dark');
}
})
Expand Down
11 changes: 7 additions & 4 deletions layouts/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,21 @@
--code-block-bg: rgb(46, 46, 51);
--code-bg: rgb(55, 56, 62);
--border: rgb(51, 51, 51);
color-scheme: dark;
}

.list {
background: var(--theme);
}

.list:not(.dark)::-webkit-scrollbar-track {
background: 0 0;
.toc {
background: var(--entry);
}
}

.list:not(.dark)::-webkit-scrollbar-thumb {
border-color: var(--theme);
@media (prefers-color-scheme: light) {
.list::-webkit-scrollbar-thumb {
border-color: var(--code-bg);
}
}

Expand Down
16 changes: 10 additions & 6 deletions layouts/partials/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,29 @@
{{- if (eq site.Params.defaultTheme "light") }}
<script>
if (localStorage.getItem("pref-theme") === "dark") {
document.body.classList.add('dark');
document.querySelector("html").dataset.theme = 'dark';
}

</script>
{{- /* theme is dark */}}
{{- else if (eq site.Params.defaultTheme "dark") }}
<script>
if (localStorage.getItem("pref-theme") === "light") {
document.body.classList.remove('dark')
document.querySelector("html").dataset.theme = 'light';
}

</script>
{{- else }}
{{- /* theme is auto */}}
<script>
if (localStorage.getItem("pref-theme") === "dark") {
document.body.classList.add('dark');
document.querySelector("html").dataset.theme = 'dark';
} else if (localStorage.getItem("pref-theme") === "light") {
document.body.classList.remove('dark')
document.querySelector("html").dataset.theme = 'light';
} else if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
document.body.classList.add('dark');
document.querySelector("html").dataset.theme = 'dark';
} else {
document.querySelector("html").dataset.theme = 'light';
}

</script>
Expand All @@ -33,7 +35,9 @@
{{- else if (and (ne site.Params.defaultTheme "light") (ne site.Params.defaultTheme "dark"))}}
<script>
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
document.body.classList.add('dark');
document.querySelector("html").dataset.theme = 'dark';
} else {
document.querySelector("html").dataset.theme = 'light';
}

</script>
Expand Down