@@ -119,15 +119,15 @@ impl HtmlHandlebars {
119
119
120
120
let mut is_index = true ;
121
121
for item in book. iter ( ) {
122
- let ctx = RenderItemContext {
122
+ let item_ctx = RenderItemContext {
123
123
handlebars : & handlebars,
124
124
destination : destination. to_path_buf ( ) ,
125
125
data : data. clone ( ) ,
126
126
is_index,
127
127
html_config : html_config. clone ( ) ,
128
128
edition : ctx. config . rust . edition ,
129
129
} ;
130
- self . render_item ( item, ctx, & mut print_content) ?;
130
+ self . render_item ( item, item_ctx , src_dir , & ctx. config , & mut print_content) ?;
131
131
is_index = false ;
132
132
}
133
133
@@ -138,6 +138,7 @@ impl HtmlHandlebars {
138
138
& html_config,
139
139
src_dir,
140
140
destination,
141
+ language_ident,
141
142
handlebars,
142
143
& mut data,
143
144
) ?;
@@ -193,6 +194,8 @@ impl HtmlHandlebars {
193
194
& self ,
194
195
item : & BookItem ,
195
196
mut ctx : RenderItemContext < ' _ > ,
197
+ src_dir : & PathBuf ,
198
+ cfg : & Config ,
196
199
print_content : & mut String ,
197
200
) -> Result < ( ) > {
198
201
// FIXME: This should be made DRY-er and rely less on mutable state
@@ -216,11 +219,29 @@ impl HtmlHandlebars {
216
219
. insert ( "git_repository_edit_url" . to_owned ( ) , json ! ( edit_url) ) ;
217
220
}
218
221
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
+ } ) ;
228
+
219
229
let content = ch. content . clone ( ) ;
220
- let content = utils:: render_markdown ( & content, ctx. html_config . curly_quotes ) ;
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
+ ) ;
221
237
222
- let fixed_content =
223
- utils:: render_markdown_with_path ( & ch. content , ctx. html_config . curly_quotes , Some ( path) ) ;
238
+ let fixed_content = utils:: render_markdown_with_path (
239
+ & ch. content ,
240
+ ctx. html_config . curly_quotes ,
241
+ Some ( & path) ,
242
+ Some ( & src_dir) ,
243
+ & fallback_path,
244
+ ) ;
224
245
if !ctx. is_index {
225
246
// Add page break between chapters
226
247
// See https://developer.mozilla.org/en-US/docs/Web/CSS/break-before and https://developer.mozilla.org/en-US/docs/Web/CSS/page-break-before
@@ -298,6 +319,7 @@ impl HtmlHandlebars {
298
319
html_config : & HtmlConfig ,
299
320
src_dir : & PathBuf ,
300
321
destination : & PathBuf ,
322
+ language_ident : & Option < String > ,
301
323
handlebars : & mut Handlebars < ' _ > ,
302
324
data : & mut serde_json:: Map < String , serde_json:: Value > ,
303
325
) -> Result < ( ) > {
@@ -321,16 +343,26 @@ impl HtmlHandlebars {
321
343
let html_content_404 = utils:: render_markdown ( & content_404, html_config. curly_quotes ) ;
322
344
323
345
let mut data_404 = data. clone ( ) ;
324
- let base_url = if let Some ( site_url) = & html_config. site_url {
325
- site_url
346
+ let mut base_url = if let Some ( site_url) = & html_config. site_url {
347
+ site_url. clone ( )
326
348
} else {
327
349
debug ! (
328
350
"HTML 'site-url' parameter not set, defaulting to '/'. Please configure \
329
351
this to ensure the 404 page work correctly, especially if your site is hosted in a \
330
352
subdirectory on the HTTP server."
331
353
) ;
332
- "/"
354
+ String :: from ( "/" )
333
355
} ;
356
+
357
+ // Set the subdirectory to the currently localized version if using a
358
+ // multilingual output format.
359
+ if let LoadedBook :: Localized ( _) = ctx. book {
360
+ if let Some ( lang_ident) = language_ident {
361
+ base_url. push_str ( lang_ident) ;
362
+ base_url. push_str ( "/" ) ;
363
+ }
364
+ }
365
+
334
366
data_404. insert ( "base_url" . to_owned ( ) , json ! ( base_url) ) ;
335
367
// Set a dummy path to ensure other paths (e.g. in the TOC) are generated correctly
336
368
data_404. insert ( "path" . to_owned ( ) , json ! ( "404.md" ) ) ;
0 commit comments