diff --git a/src/cmd/serve.rs b/src/cmd/serve.rs index 0940938f..11bd9bed 100644 --- a/src/cmd/serve.rs +++ b/src/cmd/serve.rs @@ -63,15 +63,17 @@ pub fn execute(args: &ArgMatches) -> Result<()> { let address = format!("{}:{}", hostname, port); let livereload_url = format!("ws://{}/{}", address, LIVE_RELOAD_ENDPOINT); - book.config - .set("output.html.livereload-url", &livereload_url)?; - - if let Some(dest_dir) = args.value_of("dest-dir") { - book.config.build.build_dir = dest_dir.into(); - } - // Override site-url for local serving of the 404 file - book.config.set("output.html.site-url", "/")?; - + let update_config = |book: &mut MDBook| { + book.config + .set("output.html.livereload-url", &livereload_url) + .expect("livereload-url update failed"); + if let Some(dest_dir) = args.value_of("dest-dir") { + book.config.build.build_dir = dest_dir.into(); + } + // Override site-url for local serving of the 404 file + book.config.set("output.html.site-url", "/").unwrap(); + }; + update_config(&mut book); book.build()?; let sockaddr: SocketAddr = address @@ -108,13 +110,10 @@ pub fn execute(args: &ArgMatches) -> Result<()> { info!("Building book..."); // FIXME: This area is really ugly because we need to re-set livereload :( - let result = MDBook::load(&book_dir) - .and_then(|mut b| { - b.config - .set("output.html.livereload-url", &livereload_url)?; - Ok(b) - }) - .and_then(|b| b.build()); + let result = MDBook::load(&book_dir).and_then(|mut b| { + update_config(&mut b); + b.build() + }); if let Err(e) = result { error!("Unable to load the book"); diff --git a/src/cmd/watch.rs b/src/cmd/watch.rs index f34bde39..6d972eb5 100644 --- a/src/cmd/watch.rs +++ b/src/cmd/watch.rs @@ -28,7 +28,14 @@ pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> { // Watch command implementation pub fn execute(args: &ArgMatches) -> Result<()> { let book_dir = get_book_dir(args); - let book = MDBook::load(&book_dir)?; + let mut book = MDBook::load(&book_dir)?; + + let update_config = |book: &mut MDBook| { + if let Some(dest_dir) = args.value_of("dest-dir") { + book.config.build.build_dir = dest_dir.into(); + } + }; + update_config(&mut book); if args.is_present("open") { book.build()?; @@ -37,7 +44,10 @@ pub fn execute(args: &ArgMatches) -> Result<()> { trigger_on_change(&book, |paths, book_dir| { info!("Files changed: {:?}\nBuilding book...\n", paths); - let result = MDBook::load(&book_dir).and_then(|b| b.build()); + let result = MDBook::load(&book_dir).and_then(|mut b| { + update_config(&mut b); + b.build() + }); if let Err(e) = result { error!("Unable to build the book"); diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index 24c780e2..b868f79c 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -151,7 +151,8 @@ impl HtmlHandlebars { data_404.insert("content".to_owned(), json!(html_content_404)); let rendered = handlebars.render("index", &data_404)?; - let rendered = self.post_process(rendered, &html_config.playpen, ctx.config.rust.edition); + let rendered = + self.post_process(rendered, &html_config.playground, ctx.config.rust.edition); let output_file = get_404_output_file(&html_config.input_404); utils::fs::write_file(&destination, output_file, rendered.as_bytes())?; debug!("Creating 404.html ✓");