Skip to content

Commit 7baecca

Browse files
committed
add rendered_path in the template
1 parent ec996d3 commit 7baecca

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

guide/src/format/theme/index-hbs.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Here is a list of the properties that are exposed:
2323
- ***book_title*** Title of the book, as specified in `book.toml`
2424
- ***chapter_title*** Title of the current chapter, as listed in `SUMMARY.md`
2525

26+
- ***rendered_path*** Relative path to the rendered path from the source directory
2627
- ***path*** Relative path to the original markdown file from the source
2728
directory
2829
- ***content*** This is the rendered markdown.

src/renderer/html_handlebars/hbs_renderer.rs

+8
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ impl HtmlHandlebars {
9595
ch.name.clone() + " - " + book_title
9696
};
9797

98+
let rendered_path = path.with_extension("html");
99+
100+
ctx.data
101+
.insert("rendered_path".to_owned(), json!(rendered_path));
98102
ctx.data.insert("path".to_owned(), json!(path));
99103
ctx.data.insert("content".to_owned(), json!(content));
100104
ctx.data.insert("chapter_title".to_owned(), json!(ch.name));
@@ -124,6 +128,8 @@ impl HtmlHandlebars {
124128
utils::fs::write_file(&ctx.destination, &filepath, rendered.as_bytes())?;
125129

126130
if ctx.is_index {
131+
ctx.data
132+
.insert("rendered_path".to_owned(), json!("index.html"));
127133
ctx.data.insert("path".to_owned(), json!("index.md"));
128134
ctx.data.insert("path_to_root".to_owned(), json!(""));
129135
ctx.data.insert("is_index".to_owned(), json!(true));
@@ -182,6 +188,7 @@ impl HtmlHandlebars {
182188
"/"
183189
};
184190
data_404.insert("base_url".to_owned(), json!(base_url));
191+
data_404.insert("rendered_path".to_owned(), json!("404.html"));
185192
// Set a dummy path to ensure other paths (e.g. in the TOC) are generated correctly
186193
data_404.insert("path".to_owned(), json!("404.md"));
187194
data_404.insert("content".to_owned(), json!(html_content_404));
@@ -360,6 +367,7 @@ impl HtmlHandlebars {
360367
// the last rendered chapter by removing it from its context
361368
data.remove("title");
362369
data.insert("is_print".to_owned(), json!(true));
370+
data.insert("rendered_path".to_owned(), json!("print.html"));
363371
data.insert("path".to_owned(), json!("print.md"));
364372
data.insert("content".to_owned(), json!(print_content));
365373
data.insert(

0 commit comments

Comments
 (0)