Skip to content

Commit

Permalink
Merge pull request #985 from Michael-F-Bryan/enable-caching
Browse files Browse the repository at this point in the history
Allow backends to cache previous results
  • Loading branch information
ehuss authored Aug 7, 2019
2 parents 0f56c09 + bb412ed commit aaeb3e2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
4 changes: 4 additions & 0 deletions book-example/src/for_developers/backends.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ in [`RenderContext`].
> **Note:** There is no guarantee that the destination directory exists or is
> empty (`mdbook` may leave the previous contents to let backends do caching),
> so it's always a good idea to create it with `fs::create_dir_all()`.
>
> If the destination directory already exists, don't assume it will be empty.
> To allow backends to cache the results from previous runs, `mdbook` may leave
> old content in the directory.
There's always the possibility that an error will occur while processing a book
(just look at all the `unwrap()`'s we've written already), so `mdbook` will
Expand Down
13 changes: 0 additions & 13 deletions src/book/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,19 +190,6 @@ 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 Down
5 changes: 5 additions & 0 deletions src/renderer/html_handlebars/hbs_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,11 @@ impl Renderer for HtmlHandlebars {
let destination = &ctx.destination;
let book = &ctx.book;

if destination.exists() {
utils::fs::remove_dir_content(destination)
.chain_err(|| "Unable to remove stale HTML output")?;
}

trace!("render");
let mut handlebars = Handlebars::new();

Expand Down

0 comments on commit aaeb3e2

Please sign in to comment.