File tree Expand file tree Collapse file tree 3 files changed +9
-13
lines changed
book-example/src/for_developers Expand file tree Collapse file tree 3 files changed +9
-13
lines changed Original file line number Diff line number Diff 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
265269There'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
Original file line number Diff line number Diff 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( ) ) ;
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments