Skip to content

Commit

Permalink
add rendered_path in the template
Browse files Browse the repository at this point in the history
  • Loading branch information
pinage404 committed Jul 22, 2024
1 parent ec996d3 commit 7baecca
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions guide/src/format/theme/index-hbs.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Here is a list of the properties that are exposed:
- ***book_title*** Title of the book, as specified in `book.toml`
- ***chapter_title*** Title of the current chapter, as listed in `SUMMARY.md`

- ***rendered_path*** Relative path to the rendered path from the source directory
- ***path*** Relative path to the original markdown file from the source
directory
- ***content*** This is the rendered markdown.
Expand Down
8 changes: 8 additions & 0 deletions src/renderer/html_handlebars/hbs_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ impl HtmlHandlebars {
ch.name.clone() + " - " + book_title
};

let rendered_path = path.with_extension("html");

ctx.data
.insert("rendered_path".to_owned(), json!(rendered_path));
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));
Expand Down Expand Up @@ -124,6 +128,8 @@ impl HtmlHandlebars {
utils::fs::write_file(&ctx.destination, &filepath, rendered.as_bytes())?;

if ctx.is_index {
ctx.data
.insert("rendered_path".to_owned(), json!("index.html"));
ctx.data.insert("path".to_owned(), json!("index.md"));
ctx.data.insert("path_to_root".to_owned(), json!(""));
ctx.data.insert("is_index".to_owned(), json!(true));
Expand Down Expand Up @@ -182,6 +188,7 @@ impl HtmlHandlebars {
"/"
};
data_404.insert("base_url".to_owned(), json!(base_url));
data_404.insert("rendered_path".to_owned(), json!("404.html"));
// Set a dummy path to ensure other paths (e.g. in the TOC) are generated correctly
data_404.insert("path".to_owned(), json!("404.md"));
data_404.insert("content".to_owned(), json!(html_content_404));
Expand Down Expand Up @@ -360,6 +367,7 @@ impl HtmlHandlebars {
// the last rendered chapter by removing it from its context
data.remove("title");
data.insert("is_print".to_owned(), json!(true));
data.insert("rendered_path".to_owned(), json!("print.html"));
data.insert("path".to_owned(), json!("print.md"));
data.insert("content".to_owned(), json!(print_content));
data.insert(
Expand Down

0 comments on commit 7baecca

Please sign in to comment.