From b9782b0ec2e6d3fb0d9494226101205de3ee16e8 Mon Sep 17 00:00:00 2001 From: Adam Kerrigan Date: Mon, 15 Feb 2021 17:07:07 +0000 Subject: [PATCH] have the data for the handlebars template be merged with the chapter_config preserving the chapter title --- src/renderer/html_handlebars/hbs_renderer.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index 6b934b13..bf2cf060 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -72,7 +72,9 @@ impl HtmlHandlebars { ctx.data.insert("path".to_owned(), json!(path)); ctx.data.insert("content".to_owned(), json!(content)); ctx.data.insert("chapter_title".to_owned(), json!(ch.name)); - ctx.data.insert("title".to_owned(), json!(title)); + if let Some(title) = ctx.data.insert("title".to_owned(), json!(title)) { + ctx.data.insert("title".to_string(), title); + } ctx.data.insert( "path_to_root".to_owned(), json!(utils::fs::path_to_root(&path)), @@ -494,10 +496,19 @@ impl Renderer for HtmlHandlebars { let mut is_index = true; for item in book.iter() { + let item_data = if let BookItem::Chapter(ref ch) = item { + let mut chapter_data = data.clone(); + for (key, value) in ch.chapter_config.iter() { + let _ = chapter_data.insert(key.to_string(), json!(value)); + } + chapter_data + } else { + data.clone() + }; let ctx = RenderItemContext { handlebars: &handlebars, destination: destination.to_path_buf(), - data: data.clone(), + data: item_data, is_index, html_config: html_config.clone(), edition: ctx.config.rust.edition,