From d43af7acd332b010d92ad06a3a71f3e5a52eb91f Mon Sep 17 00:00:00 2001 From: Phosphorus Date: Fri, 15 Mar 2024 01:43:00 -0300 Subject: [PATCH] feat: add slug as a handlebars variable --- src/renderer/html_handlebars/hbs_renderer.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index 3117d8e07c..a5ca2cb0ff 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -298,6 +298,11 @@ impl HtmlHandlebars { ch.name.clone() + " - " + book_title }; + let slug = Path::new(&ctx_path) + .file_stem() + .with_context(|| "Could not remove extension from path")?; + + ctx.data.insert("slug".to_owned(), json!(slug.to_str())); 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));