From b37f21a09b610c6d21523ae14562a46aa560a0f2 Mon Sep 17 00:00:00 2001 From: Rongsong Shen Date: Sat, 16 Feb 2019 12:17:26 +0800 Subject: [PATCH] Cleanup build directory before preprocessors run to keep files generated by preprocessors --- src/book/mod.rs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/book/mod.rs b/src/book/mod.rs index 48537a37..a597023b 100644 --- a/src/book/mod.rs +++ b/src/book/mod.rs @@ -167,6 +167,19 @@ impl MDBook { renderer.name().to_string(), ); + let name = renderer.name(); + let build_dir = self.build_dir_for(name); + if build_dir.exists() { + debug!( + "Cleaning build dir for the \"{}\" renderer ({})", + name, + build_dir.display() + ); + + utils::fs::remove_dir_content(&build_dir) + .chain_err(|| "Unable to clear output directory")?; + } + for preprocessor in &self.preprocessors { if preprocessor_should_run(&**preprocessor, renderer, &self.config) { debug!("Running the {} preprocessor.", preprocessor.name()); @@ -183,16 +196,6 @@ impl MDBook { fn render(&self, preprocessed_book: &Book, renderer: &Renderer) -> Result<()> { let name = renderer.name(); let build_dir = self.build_dir_for(name); - if build_dir.exists() { - debug!( - "Cleaning build dir for the \"{}\" renderer ({})", - name, - build_dir.display() - ); - - utils::fs::remove_dir_content(&build_dir) - .chain_err(|| "Unable to clear output directory")?; - } let render_context = RenderContext::new( self.root.clone(),