File tree 4 files changed +18
-1
lines changed
4 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -150,6 +150,10 @@ The following configuration options are available:
150
150
files with the ones found in the specified folder.
151
151
- ** default-theme:** The theme color scheme to select by default in the
152
152
'Change Theme' dropdown. Defaults to ` light ` .
153
+ - ** preferred-dark-theme:** The default dark theme. This theme will be used if
154
+ the browser requests the dark version of the site via the
155
+ [ 'prefers-color-scheme'] ( https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme )
156
+ CSS media query. Defaults to the same theme as ` default-theme ` .
153
157
- ** curly-quotes:** Convert straight quotes to curly quotes, except for those
154
158
that occur in code blocks and code spans. Defaults to ` false ` .
155
159
- ** mathjax-support:** Adds support for [ MathJax] ( mathjax.md ) . Defaults to
@@ -217,6 +221,7 @@ description = "The example book covers examples."
217
221
[output .html ]
218
222
theme = " my-theme"
219
223
default-theme = " light"
224
+ preferred-dark-theme = " navy"
220
225
curly-quotes = true
221
226
mathjax-support = false
222
227
google-analytics = " 123456"
Original file line number Diff line number Diff line change @@ -427,6 +427,9 @@ pub struct HtmlConfig {
427
427
pub theme : Option < PathBuf > ,
428
428
/// The default theme to use, defaults to 'light'
429
429
pub default_theme : Option < String > ,
430
+ /// The theme to use if the browser requests the dark version of the site.
431
+ /// Defaults to the same as 'default_theme'
432
+ pub preferred_dark_theme : Option < String > ,
430
433
/// Use "smart quotes" instead of the usual `"` character.
431
434
pub curly_quotes : bool ,
432
435
/// Should mathjax be enabled?
Original file line number Diff line number Diff line change @@ -406,6 +406,15 @@ fn make_data(
406
406
} ;
407
407
data. insert ( "default_theme" . to_owned ( ) , json ! ( default_theme) ) ;
408
408
409
+ let preferred_dark_theme = match html_config. preferred_dark_theme {
410
+ Some ( ref theme) => theme,
411
+ None => default_theme,
412
+ } ;
413
+ data. insert (
414
+ "preferred_dark_theme" . to_owned ( ) ,
415
+ json ! ( preferred_dark_theme) ,
416
+ ) ;
417
+
409
418
// Add google analytics tag
410
419
if let Some ( ref ga) = html_config. google_analytics {
411
420
data. insert ( "google_analytics" . to_owned ( ) , json ! ( ga) ) ;
Original file line number Diff line number Diff line change 43
43
<!-- Provide site root to javascript -->
44
44
<script type =" text/javascript" >
45
45
var path_to_root = " {{ path_to_root }}" ;
46
- var default_theme = " {{ default_theme }}" ;
46
+ var default_theme = window . matchMedia ( " (prefers-color-scheme: dark) " ). matches ? " {{ preferred_dark_theme }} " : " {{ default_theme }}" ;
47
47
</script >
48
48
49
49
<!-- Work around some values being stored in localStorage wrapped in quotes -->
You can’t perform that action at this time.
0 commit comments