@@ -11,7 +11,7 @@ use serde_json::json;
1111use std:: convert:: AsRef ;
1212use std:: error:: Error ;
1313use std:: fs:: { self , File } ;
14- use std:: io:: Write ;
14+ use std:: io:: { self , Write } ;
1515use std:: path:: { Path , PathBuf } ;
1616
1717struct Generator < ' a > {
@@ -224,17 +224,10 @@ impl<'a> Generator<'a> {
224224 }
225225
226226 fn copy_static_files ( & self ) -> Result < ( ) , Box < dyn Error > > {
227- use fs_extra:: dir:: { self , CopyOptions } ;
228-
229- let mut options = CopyOptions :: new ( ) ;
230- options. overwrite = true ;
231- options. copy_inside = true ;
232-
233- dir:: copy ( "static/fonts" , & self . out_directory , & options) ?;
234- dir:: copy ( "static/images" , & self . out_directory , & options) ?;
235- dir:: copy ( "static/styles" , & self . out_directory , & options) ?;
236- dir:: copy ( "static/scripts" , & self . out_directory , & options) ?;
237-
227+ copy_dir ( "static/fonts" , & self . out_directory ) ?;
228+ copy_dir ( "static/images" , & self . out_directory ) ?;
229+ copy_dir ( "static/styles" , & self . out_directory ) ?;
230+ copy_dir ( "static/scripts" , & self . out_directory ) ?;
238231 Ok ( ( ) )
239232 }
240233
@@ -251,6 +244,26 @@ impl<'a> Generator<'a> {
251244 }
252245}
253246
247+ fn copy_dir ( source : impl AsRef < Path > , dest : impl AsRef < Path > ) -> Result < ( ) , io:: Error > {
248+ let source = source. as_ref ( ) ;
249+ let dest = dest. as_ref ( ) . join ( source. file_name ( ) . unwrap ( ) ) ;
250+ assert ! ( source. is_dir( ) ) ;
251+ fn copy_inner ( source : & Path , dest : & Path ) -> Result < ( ) , io:: Error > {
252+ fs:: create_dir_all ( dest) ?;
253+ for entry in fs:: read_dir ( source) ? {
254+ let entry = entry?;
255+ let new_dest = dest. join ( entry. file_name ( ) ) ;
256+ if entry. file_type ( ) ?. is_dir ( ) {
257+ copy_inner ( & entry. path ( ) , & new_dest) ?;
258+ } else {
259+ fs:: copy ( & entry. path ( ) , & new_dest) ?;
260+ }
261+ }
262+ Ok ( ( ) )
263+ }
264+ copy_inner ( source, & dest)
265+ }
266+
254267pub fn main ( ) -> Result < ( ) , Box < dyn Error > > {
255268 let blog = Generator :: new ( "site" , "posts" ) ?;
256269
0 commit comments