mirror of
https://github.com/rust-lang/mdBook
synced 2024-12-13 22:32:35 +00:00
Merge pull request #985 from Michael-F-Bryan/enable-caching
Allow backends to cache previous results
This commit is contained in:
commit
aaeb3e2852
3 changed files with 9 additions and 13 deletions
|
@ -261,6 +261,10 @@ in [`RenderContext`].
|
||||||
> **Note:** There is no guarantee that the destination directory exists or is
|
> **Note:** There is no guarantee that the destination directory exists or is
|
||||||
> empty (`mdbook` may leave the previous contents to let backends do caching),
|
> 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()`.
|
> 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
|
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
|
(just look at all the `unwrap()`'s we've written already), so `mdbook` will
|
||||||
|
|
|
@ -190,19 +190,6 @@ impl MDBook {
|
||||||
renderer.name().to_string(),
|
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 {
|
for preprocessor in &self.preprocessors {
|
||||||
if preprocessor_should_run(&**preprocessor, renderer, &self.config) {
|
if preprocessor_should_run(&**preprocessor, renderer, &self.config) {
|
||||||
debug!("Running the {} preprocessor.", preprocessor.name());
|
debug!("Running the {} preprocessor.", preprocessor.name());
|
||||||
|
|
|
@ -282,6 +282,11 @@ impl Renderer for HtmlHandlebars {
|
||||||
let destination = &ctx.destination;
|
let destination = &ctx.destination;
|
||||||
let book = &ctx.book;
|
let book = &ctx.book;
|
||||||
|
|
||||||
|
if destination.exists() {
|
||||||
|
utils::fs::remove_dir_content(destination)
|
||||||
|
.chain_err(|| "Unable to remove stale HTML output")?;
|
||||||
|
}
|
||||||
|
|
||||||
trace!("render");
|
trace!("render");
|
||||||
let mut handlebars = Handlebars::new();
|
let mut handlebars = Handlebars::new();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue