From 2e812db13cc3757d41bfe011c8f82e8dae0b95e3 Mon Sep 17 00:00:00 2001 From: Mathieu David Date: Fri, 19 May 2017 01:13:45 +0200 Subject: [PATCH] Fix for google-analytics --- src/book/mod.rs | 11 ++++++++--- src/renderer/html_handlebars/hbs_renderer.rs | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) 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)); }