Skip to content

Commit aaeb3e2

Browse files
authored
Merge pull request #985 from Michael-F-Bryan/enable-caching
Allow backends to cache previous results
2 parents 0f56c09 + bb412ed commit aaeb3e2

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

book-example/src/for_developers/backends.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,10 @@ in [`RenderContext`].
261261
> **Note:** There is no guarantee that the destination directory exists or is
262262
> empty (`mdbook` may leave the previous contents to let backends do caching),
263263
> so it's always a good idea to create it with `fs::create_dir_all()`.
264+
>
265+
> If the destination directory already exists, don't assume it will be empty.
266+
> To allow backends to cache the results from previous runs, `mdbook` may leave
267+
> old content in the directory.
264268
265269
There's always the possibility that an error will occur while processing a book
266270
(just look at all the `unwrap()`'s we've written already), so `mdbook` will

src/book/mod.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -190,19 +190,6 @@ impl MDBook {
190190
renderer.name().to_string(),
191191
);
192192

193-
let name = renderer.name();
194-
let build_dir = self.build_dir_for(name);
195-
if build_dir.exists() {
196-
debug!(
197-
"Cleaning build dir for the \"{}\" renderer ({})",
198-
name,
199-
build_dir.display()
200-
);
201-
202-
utils::fs::remove_dir_content(&build_dir)
203-
.chain_err(|| "Unable to clear output directory")?;
204-
}
205-
206193
for preprocessor in &self.preprocessors {
207194
if preprocessor_should_run(&**preprocessor, renderer, &self.config) {
208195
debug!("Running the {} preprocessor.", preprocessor.name());

src/renderer/html_handlebars/hbs_renderer.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,11 @@ impl Renderer for HtmlHandlebars {
282282
let destination = &ctx.destination;
283283
let book = &ctx.book;
284284

285+
if destination.exists() {
286+
utils::fs::remove_dir_content(destination)
287+
.chain_err(|| "Unable to remove stale HTML output")?;
288+
}
289+
285290
trace!("render");
286291
let mut handlebars = Handlebars::new();
287292

0 commit comments

Comments
 (0)