diff --git a/src/book/mod.rs b/src/book/mod.rs index 9125dc68..c3765ff0 100644 --- a/src/book/mod.rs +++ b/src/book/mod.rs @@ -29,8 +29,6 @@ pub struct MDBook { /// Should `mdbook build` create files referenced from SUMMARY.md if they /// don't exist pub create_missing: bool, - - pub google_analytics: Option, } impl MDBook { @@ -75,7 +73,6 @@ impl MDBook { livereload: None, create_missing: true, - google_analytics: None, } } @@ -492,6 +489,14 @@ impl MDBook { None } + pub fn get_google_analytics_id(&self) -> Option { + if let Some(htmlconfig) = self.config.get_html_config() { + return htmlconfig.get_google_analytics_id(); + } + + None + } + // Construct book fn parse_summary(&mut self) -> Result<(), Box> { // When append becomes stable, use self.content.append() ... diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index 16f1ccd9..29fca838 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -211,7 +211,7 @@ fn make_data(book: &MDBook) -> Result } // Add google analytics tag - if let Some(ref ga) = book.google_analytics { + if let Some(ref ga) = book.get_google_analytics_id() { data.insert("google_analytics".to_owned(), json!(ga)); }