From 94dce4f796e8152aa0ffa9835034c170f9956b2c Mon Sep 17 00:00:00 2001 From: Michael-F-Bryan Date: Tue, 16 May 2017 13:24:05 +0800 Subject: [PATCH] Added google_analytics so it can be inserted into handlebars --- src/book/mod.rs | 3 +++ src/renderer/html_handlebars/hbs_renderer.rs | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/book/mod.rs b/src/book/mod.rs index 85d20a79..5e413c87 100644 --- a/src/book/mod.rs +++ b/src/book/mod.rs @@ -36,6 +36,8 @@ 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 { @@ -84,6 +86,7 @@ impl MDBook { livereload: None, create_missing: true, + google_analytics: None, } } diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index 1d84c73d..e9250a3d 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -194,7 +194,9 @@ fn make_data(book: &MDBook) -> Result } // Add google analytics tag - data.insert("google_analytics".to_owned(), json!("INSERT_GA_ID_HERE")); + if let Some(ref ga) = book.google_analytics { + data.insert("google_analytics".to_owned(), json!(ga)); + } let mut chapters = vec![];