@@ -4,7 +4,7 @@ use crate::errors::*;
4
4
use crate :: renderer:: html_handlebars:: helpers;
5
5
use crate :: renderer:: { RenderContext , Renderer } ;
6
6
use crate :: theme:: { self , playground_editor, Theme } ;
7
- use crate :: utils;
7
+ use crate :: utils:: { self , RenderMarkdownContext } ;
8
8
9
9
use std:: borrow:: Cow ;
10
10
use std:: collections:: BTreeMap ;
@@ -35,14 +35,12 @@ impl HtmlHandlebars {
35
35
match ctx. book {
36
36
LoadedBook :: Localized ( ref books) => {
37
37
for ( lang_ident, book) in books. 0 . iter ( ) {
38
- let localized_src_dir = src_dir. join ( lang_ident) ;
39
38
let localized_destination = ctx. destination . join ( lang_ident) ;
40
39
let localized_build_dir = ctx. config . build . build_dir . join ( lang_ident) ;
41
40
self . render_book (
42
41
ctx,
43
42
& book,
44
- & localized_src_dir,
45
- & localized_src_dir,
43
+ src_dir,
46
44
& localized_destination,
47
45
& localized_build_dir,
48
46
& Some ( lang_ident. to_string ( ) ) ,
@@ -53,27 +51,10 @@ impl HtmlHandlebars {
53
51
}
54
52
}
55
53
LoadedBook :: Single ( ref book) => {
56
- // `src_dir` points to the root source directory. If this book
57
- // is actually multilingual and we specified a single language
58
- // to build on the command line, then `src_dir` will not be
59
- // pointing at the subdirectory with the specified translation's
60
- // index/summary files. We have to append the language
61
- // identifier to prevent the files from the other translations
62
- // from being copied in the final step.
63
- let extra_file_dir = match & ctx. build_opts . language_ident {
64
- Some ( lang_ident) => {
65
- let mut path = src_dir. clone ( ) ;
66
- path. push ( lang_ident) ;
67
- path
68
- }
69
- None => src_dir. clone ( ) ,
70
- } ;
71
-
72
54
self . render_book (
73
55
ctx,
74
56
& book,
75
57
src_dir,
76
- & extra_file_dir,
77
58
& ctx. destination ,
78
59
& ctx. config . build . build_dir ,
79
60
& ctx. build_opts . language_ident ,
@@ -92,10 +73,9 @@ impl HtmlHandlebars {
92
73
ctx : & RenderContext ,
93
74
book : & Book ,
94
75
src_dir : & PathBuf ,
95
- extra_file_dir : & PathBuf ,
96
76
destination : & PathBuf ,
97
77
build_dir : & PathBuf ,
98
- language_ident : & Option < String > ,
78
+ language : & Option < String > ,
99
79
html_config : & HtmlConfig ,
100
80
handlebars : & mut Handlebars < ' a > ,
101
81
theme : & Theme ,
@@ -106,7 +86,7 @@ impl HtmlHandlebars {
106
86
& book,
107
87
& ctx. book ,
108
88
& ctx. config ,
109
- language_ident ,
89
+ language ,
110
90
& html_config,
111
91
& theme,
112
92
) ?;
@@ -127,7 +107,14 @@ impl HtmlHandlebars {
127
107
html_config : html_config. clone ( ) ,
128
108
edition : ctx. config . rust . edition ,
129
109
} ;
130
- self . render_item ( item, item_ctx, src_dir, & ctx. config , & mut print_content) ?;
110
+ self . render_item (
111
+ item,
112
+ item_ctx,
113
+ & src_dir,
114
+ language,
115
+ & ctx. config ,
116
+ & mut print_content,
117
+ ) ?;
131
118
is_index = false ;
132
119
}
133
120
@@ -136,9 +123,9 @@ impl HtmlHandlebars {
136
123
self . render_404 (
137
124
ctx,
138
125
& html_config,
139
- src_dir,
126
+ & src_dir,
140
127
destination,
141
- language_ident ,
128
+ language ,
142
129
handlebars,
143
130
& mut data,
144
131
) ?;
@@ -178,6 +165,28 @@ impl HtmlHandlebars {
178
165
self . emit_redirects ( & ctx. destination , handlebars, & html_config. redirect )
179
166
. context ( "Unable to emit redirects" ) ?;
180
167
168
+ // `src_dir` points to the root source directory. If this book
169
+ // is actually multilingual and we specified a single language
170
+ // to build on the command line, then `src_dir` will not be
171
+ // pointing at the subdirectory with the specified translation's
172
+ // index/summary files. We have to append the language
173
+ // identifier to prevent the files from the other translations
174
+ // from being copied in the final step.
175
+ let extra_file_dir = match language {
176
+ Some ( lang_ident) => {
177
+ // my_book/src/ja/
178
+ let mut path = src_dir. clone ( ) ;
179
+ path. push ( lang_ident) ;
180
+ path
181
+ }
182
+ // my_book/src/
183
+ None => src_dir. clone ( ) ,
184
+ } ;
185
+ debug ! (
186
+ "extra file dir {:?} {:?} {:?}" ,
187
+ extra_file_dir, language, ctx. config
188
+ ) ;
189
+
181
190
// Copy all remaining files, avoid a recursive copy from/to the book build dir
182
191
utils:: fs:: copy_files_except_ext (
183
192
& extra_file_dir,
@@ -195,6 +204,7 @@ impl HtmlHandlebars {
195
204
item : & BookItem ,
196
205
mut ctx : RenderItemContext < ' _ > ,
197
206
src_dir : & PathBuf ,
207
+ language : & Option < String > ,
198
208
cfg : & Config ,
199
209
print_content : & mut String ,
200
210
) -> Result < ( ) > {
@@ -219,28 +229,32 @@ impl HtmlHandlebars {
219
229
. insert ( "git_repository_edit_url" . to_owned ( ) , json ! ( edit_url) ) ;
220
230
}
221
231
222
- let fallback_path = cfg. default_language ( ) . map ( |lang_ident| {
223
- let mut fallback = PathBuf :: from ( utils:: fs:: path_to_root ( & path) ) ;
224
- fallback. push ( "../" ) ;
225
- fallback. push ( lang_ident. clone ( ) ) ;
226
- fallback
227
- } ) ;
232
+ let mut md_ctx = match language {
233
+ Some ( lang_ident) => RenderMarkdownContext {
234
+ path : path. clone ( ) ,
235
+ src_dir : src_dir. clone ( ) ,
236
+ language : Some ( lang_ident. clone ( ) ) ,
237
+ fallback_language : cfg. default_language ( ) ,
238
+ prepend_parent : false ,
239
+ } ,
240
+ None => RenderMarkdownContext {
241
+ path : path. clone ( ) ,
242
+ src_dir : src_dir. clone ( ) ,
243
+ language : None ,
244
+ fallback_language : None ,
245
+ prepend_parent : false ,
246
+ } ,
247
+ } ;
228
248
229
249
let content = ch. content . clone ( ) ;
230
- let content = utils:: render_markdown_with_path (
231
- & content,
232
- ctx. html_config . curly_quotes ,
233
- Some ( & path) ,
234
- Some ( & src_dir) ,
235
- & fallback_path,
236
- ) ;
250
+ let content =
251
+ utils:: render_markdown_with_path ( & content, ctx. html_config . curly_quotes , Some ( & md_ctx) ) ;
237
252
253
+ md_ctx. prepend_parent = true ;
238
254
let fixed_content = utils:: render_markdown_with_path (
239
255
& ch. content ,
240
256
ctx. html_config . curly_quotes ,
241
- Some ( & path) ,
242
- Some ( & src_dir) ,
243
- & fallback_path,
257
+ Some ( & md_ctx) ,
244
258
) ;
245
259
if !ctx. is_index {
246
260
// Add page break between chapters
0 commit comments