diff --git a/examples/nop-preprocessor.rs b/examples/nop-preprocessor.rs index 398d7fc7..fb24d53a 100644 --- a/examples/nop-preprocessor.rs +++ b/examples/nop-preprocessor.rs @@ -138,7 +138,8 @@ mod nop_lib { "sub_items": [], "path": "chapter_1.md", "source_path": "chapter_1.md", - "parent_names": [] + "parent_names": [], + "data": {} } } ], diff --git a/src/book/book.rs b/src/book/book.rs index 96c70abc..ee25c25f 100644 --- a/src/book/book.rs +++ b/src/book/book.rs @@ -165,6 +165,9 @@ pub struct Chapter { pub source_path: Option, /// An ordered list of the names of each chapter above this one in the hierarchy. pub parent_names: Vec, + /// Data that can be shared between preprocessors, accessed in the renderer + /// or accessed in the theme's `.hbs` files + pub data: serde_json::Map, } impl Chapter { @@ -444,6 +447,7 @@ And here is some \ source_path: Some(PathBuf::from("second.md")), parent_names: vec![String::from("Chapter 1")], sub_items: Vec::new(), + data: serde_json::Map::new(), }; let should_be = BookItem::Chapter(Chapter { name: String::from("Chapter 1"), @@ -457,6 +461,7 @@ And here is some \ BookItem::Separator, BookItem::Chapter(nested), ], + data: serde_json::Map::new(), }); let got = load_summary_item(&SummaryItem::Link(root), temp.path(), Vec::new()).unwrap(); @@ -533,6 +538,7 @@ And here is some \ Vec::new(), )), ], + data: serde_json::Map::new(), }), BookItem::Separator, ], @@ -586,6 +592,7 @@ And here is some \ Vec::new(), )), ], + data: serde_json::Map::new(), }), BookItem::Separator, ], diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index 709aa066..fabcf40e 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -105,6 +105,7 @@ impl HtmlHandlebars { ctx.data .insert("section".to_owned(), json!(section.to_string())); } + ctx.data.insert("data".to_owned(), json!(ch.data)); // Render the handlebars template with the data debug!("Render template");