mirror of
https://github.com/rust-lang/mdBook
synced 2024-12-13 22:32:35 +00:00
Add current chapter title to handlebars context
This commit is contained in:
parent
f1df53a4bb
commit
3a0cfc87df
3 changed files with 6 additions and 2 deletions
|
@ -20,6 +20,7 @@ Here is a list of the properties that are exposed:
|
|||
- ***language*** Language of the book in the form `en`. To use in <code class="language-html">\<html lang="{{ language }}"></code> for example.
|
||||
At the moment it is hardcoded.
|
||||
- ***title*** Title of the book, as specified in `book.toml`
|
||||
- ***chapter_title*** Title of the current chapter, as listed in `SUMMARY.md`
|
||||
|
||||
- ***path*** Relative path to the original markdown file from the source directory
|
||||
- ***content*** This is the rendered markdown.
|
||||
|
|
|
@ -93,11 +93,14 @@ impl Renderer for HtmlHandlebars {
|
|||
},
|
||||
}
|
||||
|
||||
|
||||
// Remove content from previous file and render content for this one
|
||||
data.remove("content");
|
||||
data.insert("content".to_owned(), content.to_json());
|
||||
|
||||
// Remove chapter title from previous file and add title for this one
|
||||
data.remove("chapter_title");
|
||||
data.insert("chapter_title".to_owned(), ch.name.to_json());
|
||||
|
||||
// Remove path to root from previous file and render content for this one
|
||||
data.remove("path_to_root");
|
||||
data.insert("path_to_root".to_owned(), utils::fs::path_to_root(&ch.path).to_json());
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<html lang="{{ language }}">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>{{ title }}</title>
|
||||
<title>{{ chapter_title }} - {{ title }}</title>
|
||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
||||
<meta name="description" content="{{ description }}">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
|
Loading…
Reference in a new issue