Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add rendered_path in the template #2415

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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