@@ -7,7 +7,6 @@ pub mod tpls;
77
88use std:: borrow:: Cow ;
99use std:: collections:: { HashMap , HashSet } ;
10- use std:: fs:: { remove_dir_all, remove_file} ;
1110use std:: path:: { Path , PathBuf } ;
1211use std:: sync:: { Arc , Mutex , RwLock } ;
1312
@@ -18,13 +17,13 @@ use libs::walkdir::{DirEntry, WalkDir};
1817
1918use config:: { get_config, Config , IndexFormat } ;
2019use content:: { Library , Page , Paginator , Section , Taxonomy } ;
21- use errors:: { anyhow, bail, Context as ErrorContext , Result } ;
20+ use errors:: { anyhow, bail, Result } ;
2221use libs:: relative_path:: RelativePathBuf ;
2322use std:: time:: Instant ;
2423use templates:: { load_tera, render_redirect_template} ;
2524use 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 ,
2827} ;
2928use utils:: net:: { get_available_port, is_external_link} ;
3029use utils:: templates:: { render_template, ShortcodeDefinition } ;
@@ -613,34 +612,7 @@ impl Site {
613612 /// Deletes the `public` directory if it exists and the `preserve_dotfiles_in_output` option is set to false,
614613 /// or if set to true: its contents except for the dotfiles at the root level.
615614 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 )
644616 }
645617
646618 /// Handles whether to write to disk or to memory
0 commit comments