@@ -7,7 +7,6 @@ pub mod tpls;
7
7
8
8
use std:: borrow:: Cow ;
9
9
use std:: collections:: { HashMap , HashSet } ;
10
- use std:: fs:: { remove_dir_all, remove_file} ;
11
10
use std:: path:: { Path , PathBuf } ;
12
11
use std:: sync:: { Arc , Mutex , RwLock } ;
13
12
@@ -18,13 +17,13 @@ use libs::walkdir::{DirEntry, WalkDir};
18
17
19
18
use config:: { get_config, Config , IndexFormat } ;
20
19
use content:: { Library , Page , Paginator , Section , Taxonomy } ;
21
- use errors:: { anyhow, bail, Context as ErrorContext , Result } ;
20
+ use errors:: { anyhow, bail, Result } ;
22
21
use libs:: relative_path:: RelativePathBuf ;
23
22
use std:: time:: Instant ;
24
23
use templates:: { load_tera, render_redirect_template} ;
25
24
use utils:: fs:: {
26
- copy_directory, copy_file_if_needed, create_directory, create_file, ensure_directory_exists ,
27
- is_dotfile ,
25
+ clean_site_output_folder , copy_directory, copy_file_if_needed, create_directory, create_file,
26
+ ensure_directory_exists ,
28
27
} ;
29
28
use utils:: net:: { get_available_port, is_external_link} ;
30
29
use utils:: templates:: { render_template, ShortcodeDefinition } ;
@@ -613,34 +612,7 @@ impl Site {
613
612
/// Deletes the `public` directory if it exists and the `preserve_dotfiles_in_output` option is set to false,
614
613
/// or if set to true: its contents except for the dotfiles at the root level.
615
614
pub fn clean ( & self ) -> Result < ( ) > {
616
- if self . output_path . exists ( ) {
617
- if !self . config . preserve_dotfiles_in_output {
618
- return remove_dir_all ( & self . output_path )
619
- . context ( "Couldn't delete output directory" ) ;
620
- }
621
-
622
- for entry in self . output_path . read_dir ( ) . context ( format ! (
623
- "Couldn't read output directory `{}`" ,
624
- self . output_path. display( )
625
- ) ) ? {
626
- let entry = entry. context ( "Couldn't read entry in output directory" ) ?. path ( ) ;
627
-
628
- // Skip dotfiles if the preserve_dotfiles_in_output configuration option is set
629
- if is_dotfile ( & entry) {
630
- continue ;
631
- }
632
-
633
- if entry. is_dir ( ) {
634
- remove_dir_all ( entry)
635
- . context ( "Couldn't delete folder while cleaning the output directory" ) ?;
636
- } else {
637
- remove_file ( entry)
638
- . context ( "Couldn't delete file while cleaning the output directory" ) ?;
639
- }
640
- }
641
- }
642
-
643
- Ok ( ( ) )
615
+ clean_site_output_folder ( & self . output_path , self . config . preserve_dotfiles_in_output )
644
616
}
645
617
646
618
/// Handles whether to write to disk or to memory
0 commit comments