Skip to content

Commit

Permalink
Cleanup build directory before preprocessors run to keep files genera…
Browse files Browse the repository at this point in the history
…ted by preprocessors
  • Loading branch information
Rongsong Shen committed Feb 16, 2019
1 parent c068703 commit b37f21a
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/book/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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(),
Expand Down

1 comment on commit b37f21a

@shen390s
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to use preprocessor to executable some special code block to generate some diagram(such as using dot to generate diagrams for code block written to dot language), so I need to keep the generated files by preprocessors.

Please sign in to comment.