@@ -224,13 +224,19 @@ impl HtmlHandlebars {
224
224
} ;
225
225
226
226
if let Some ( ref edit_url_template) = ctx. html_config . edit_url_template {
227
- let full_path = ctx. book_config . src . to_str ( ) . unwrap_or_default ( ) . to_owned ( )
228
- + "/"
229
- + ch. source_path
230
- . clone ( )
231
- . unwrap_or_default ( )
232
- . to_str ( )
233
- . unwrap_or_default ( ) ;
227
+ let mut full_path = ctx. book_config . src . to_str ( ) . unwrap_or_default ( ) . to_owned ( ) ;
228
+
229
+ if let Some ( lang) = language. clone ( ) {
230
+ full_path = full_path + "/" + & lang;
231
+ }
232
+
233
+ full_path = full_path
234
+ + "/"
235
+ + ch. source_path
236
+ . clone ( )
237
+ . unwrap_or_default ( )
238
+ . to_str ( )
239
+ . unwrap_or_default ( ) ;
234
240
235
241
let edit_url = edit_url_template. replace ( "{path}" , & full_path) ;
236
242
ctx. data
@@ -298,11 +304,21 @@ impl HtmlHandlebars {
298
304
ch. name . clone ( ) + " - " + book_title
299
305
} ;
300
306
301
- let slug = Path :: new ( & ctx_path)
302
- . file_stem ( )
303
- . with_context ( || "Could not remove extension from path" ) ?;
307
+ let slug = ctx_path. replace ( ".md" , "" ) ;
308
+
309
+ let mut base_url = if let Some ( site_url) = & ctx. html_config . site_url {
310
+ site_url. clone ( )
311
+ } else {
312
+ debug ! (
313
+ "HTML 'site-url' parameter not set, defaulting to '/'. Please configure \
314
+ this to ensure the 404 page work correctly, especially if your site is hosted in a \
315
+ subdirectory on the HTTP server."
316
+ ) ;
317
+ String :: from ( "/" )
318
+ } ;
304
319
305
- ctx. data . insert ( "slug" . to_owned ( ) , json ! ( slug. to_str( ) ) ) ;
320
+ ctx. data . insert ( "base_url" . to_owned ( ) , json ! ( base_url) ) ;
321
+ ctx. data . insert ( "slug" . to_owned ( ) , json ! ( slug) ) ;
306
322
ctx. data . insert ( "path" . to_owned ( ) , json ! ( path) ) ;
307
323
ctx. data . insert ( "content" . to_owned ( ) , json ! ( content) ) ;
308
324
ctx. data . insert ( "chapter_title" . to_owned ( ) , json ! ( ch. name) ) ;
0 commit comments