@@ -224,13 +224,19 @@ impl HtmlHandlebars {
224224 } ;
225225
226226 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 ( ) ;
234240
235241 let edit_url = edit_url_template. replace ( "{path}" , & full_path) ;
236242 ctx. data
@@ -298,11 +304,21 @@ impl HtmlHandlebars {
298304 ch. name . clone ( ) + " - " + book_title
299305 } ;
300306
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+ } ;
304319
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) ) ;
306322 ctx. data . insert ( "path" . to_owned ( ) , json ! ( path) ) ;
307323 ctx. data . insert ( "content" . to_owned ( ) , json ! ( content) ) ;
308324 ctx. data . insert ( "chapter_title" . to_owned ( ) , json ! ( ch. name) ) ;
0 commit comments