diff --git a/src/config.rs b/src/config.rs index 17c941d2..21b5452e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -420,6 +420,11 @@ pub struct HtmlConfig { pub theme: Option, /// The default theme to use, defaults to 'light' pub default_theme: Option, + /// The default dark theme. + /// This theme will be used if the browser requests a dark theme + /// via the 'prefers-color-scheme' CSS media query. + /// Defaults to 'navy'. + pub preferred_dark_theme: Option, /// Use "smart quotes" instead of the usual `"` character. pub curly_quotes: bool, /// Should mathjax be enabled? diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index 7a7f0ef6..e9f70225 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -407,6 +407,15 @@ fn make_data( }; data.insert("default_theme".to_owned(), json!(default_theme)); + let preferred_dark_theme = match html_config.preferred_dark_theme { + Some(ref theme) => theme, + None => "navy", + }; + data.insert( + "preferred_dark_theme".to_owned(), + json!(preferred_dark_theme), + ); + // Add google analytics tag if let Some(ref ga) = config.html_config().and_then(|html| html.google_analytics) { data.insert("google_analytics".to_owned(), json!(ga)); diff --git a/src/theme/index.hbs b/src/theme/index.hbs index 4e29807c..26800ad5 100644 --- a/src/theme/index.hbs +++ b/src/theme/index.hbs @@ -43,7 +43,7 @@