File tree Expand file tree Collapse file tree 3 files changed +11
-8
lines changed
Expand file tree Collapse file tree 3 files changed +11
-8
lines changed Original file line number Diff line number Diff line change @@ -10,8 +10,8 @@ infrastructure for [mdbook](https://github.com/rust-lang/mdBook/):
1010
1111- [ mdbook-i18n-helpers] ( i18n-helpers/README.md ) : Gettext translation support for
1212 [ mdbook] ( https://github.com/rust-lang/mdBook/ )
13- - [ mdbook-tera-backend] ( ./mdbook-tera-backend/README.md ) : Tera templates extension
14- for [ mdbook] ( https://github.com/rust-lang/mdBook/ ) 's HTML renderer.
13+ - [ mdbook-tera-backend] ( ./mdbook-tera-backend/README.md ) : Tera templates
14+ extension for [ mdbook] ( https://github.com/rust-lang/mdBook/ ) 's HTML renderer.
1515
1616## Showcases
1717
Original file line number Diff line number Diff line change 55[ ![ GitHub contributors] ( https://img.shields.io/github/contributors/google/mdbook-i18n-helpers?style=flat-square )] ( https://github.com/google/mdbook-i18n-helpers/graphs/contributors )
66[ ![ GitHub stars] ( https://img.shields.io/github/stars/google/mdbook-i18n-helpers?style=flat-square )] ( https://github.com/google/mdbook-i18n-helpers/stargazers )
77
8- This ` mdbook ` backend makes it possible to use [ tera ] ( https://github.com/Keats/tera )
9- templates and expand the capabilities of your books. It works on top of the default HTML
10- backend.
8+ This ` mdbook ` backend makes it possible to use
9+ [ tera ] ( https://github.com/Keats/tera ) templates and expand the capabilities of
10+ your books. It works on top of the default HTML backend.
1111
1212## Installation
1313
Original file line number Diff line number Diff line change @@ -62,8 +62,9 @@ impl Renderer {
6262 /// `path`: The path to the file that will be added as extra context to the renderer.
6363 fn create_context ( & mut self , path : & Path ) -> Result < tera:: Context > {
6464 let mut context = tera:: Context :: new ( ) ;
65- context. insert ( "path" , path) ;
66- context. insert ( "ctx" , & serde_json:: to_value ( & self . ctx ) ?) ;
65+ let book_dir = self . ctx . destination . parent ( ) . unwrap ( ) ;
66+ let relative_path = path. strip_prefix ( book_dir) . unwrap ( ) ;
67+ context. insert ( "path" , & relative_path) ;
6768 context. insert ( "book_dir" , & self . ctx . destination . parent ( ) . unwrap ( ) ) ;
6869
6970 Ok ( context)
@@ -126,7 +127,8 @@ mod test {
126127
127128 const HTML_FILE : & str = r#"
128129 <!DOCTYPE html>
129- {%include "test_template.html" %}
130+ {% include "test_template.html" %}
131+ PATH: {{ path }}
130132 </html>
131133 "# ;
132134
@@ -135,6 +137,7 @@ mod test {
135137 const RENDERED_HTML_FILE : & str = r#"
136138 <!DOCTYPE html>
137139 RENDERED
140+ PATH: html/test.html
138141 </html>
139142 "# ;
140143
You can’t perform that action at this time.
0 commit comments