diff --git a/src/config.rs b/src/config.rs index 655d3da0..bc57472c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -415,6 +415,8 @@ impl Default for BuildConfig { pub struct HtmlConfig { /// The theme directory, if specified. pub theme: Option, + /// The default theme to use, defaults to 'light' + pub default_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 3f87ba4d..fe80259e 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -395,6 +395,12 @@ fn make_data( data.insert("livereload".to_owned(), json!(livereload)); } + let default_theme = match html_config.default_theme { + Some(ref theme) => theme, + None => "light", + }; + data.insert("default_theme".to_owned(), json!(default_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/book.js b/src/theme/book.js index c9c2f4d6..4640e8fc 100644 --- a/src/theme/book.js +++ b/src/theme/book.js @@ -352,7 +352,7 @@ function playpen_text(playpen) { var previousTheme; try { previousTheme = localStorage.getItem('mdbook-theme'); } catch (e) { } - if (previousTheme === null || previousTheme === undefined) { previousTheme = 'light'; } + if (previousTheme === null || previousTheme === undefined) { previousTheme = default_theme; } try { localStorage.setItem('mdbook-theme', theme); } catch (e) { } @@ -364,7 +364,7 @@ function playpen_text(playpen) { // Set theme var theme; try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { } - if (theme === null || theme === undefined) { theme = 'light'; } + if (theme === null || theme === undefined) { theme = default_theme; } set_theme(theme); diff --git a/src/theme/index.hbs b/src/theme/index.hbs index 982c2f7d..744916d4 100644 --- a/src/theme/index.hbs +++ b/src/theme/index.hbs @@ -35,9 +35,12 @@ {{/if}} - + - + @@ -94,7 +97,7 @@