Skip to content

Commit 79b4e58

Browse files
giscus light and dark: author preference determines which theme is alternate
1 parent c42a477 commit 79b4e58

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/resources/formats/html/giscus/giscus.ejs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
function loadGiscusWhenReady() {
55
// Function to get the theme based on body class
66
const getTheme = () => {
7-
const baseTheme = document.getElementById('giscus-base-theme').value;
8-
const altTheme = document.getElementById('giscus-alt-theme').value;
7+
let baseTheme = document.getElementById('giscus-base-theme').value;
8+
let altTheme = document.getElementById('giscus-alt-theme').value;
9+
if (authorPrefersDark) {
10+
[baseTheme, altTheme] = [altTheme, baseTheme];
11+
}
912
return document.body.classList.contains('quarto-dark') ? altTheme : baseTheme;
1013
};
1114

src/resources/formats/html/templates/quarto-html-before-body.ejs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
137137
let newTheme = '';
138138
139-
if(darkModeDefault) {
139+
if(authorPrefersDark) {
140140
newTheme = isAlternate ? baseTheme : alternateTheme;
141141
} else {
142142
newTheme = isAlternate ? alternateTheme : baseTheme;
@@ -165,10 +165,12 @@
165165
};
166166
167167
<% if (respectUserColorScheme) { %>
168+
const authorPrefersDark = <%= darkModeDefault %>;
168169
const queryPrefersDark = window.matchMedia('(prefers-color-scheme: dark)');
169170
const darkModeDefault = queryPrefersDark.matches;
170171
<% } else { %>
171172
const darkModeDefault = <%= darkModeDefault %>;
173+
const authorPrefersDark = <%= darkModeDefault %>;
172174
<% } %>
173175
174176
<% if (!darkModeDefault) { %>

0 commit comments

Comments
 (0)