@@ -11,7 +11,7 @@ use serde_json::json;
11
11
use std:: convert:: AsRef ;
12
12
use std:: error:: Error ;
13
13
use std:: fs:: { self , File } ;
14
- use std:: io:: Write ;
14
+ use std:: io:: { self , Write } ;
15
15
use std:: path:: { Path , PathBuf } ;
16
16
17
17
struct Generator < ' a > {
@@ -224,17 +224,10 @@ impl<'a> Generator<'a> {
224
224
}
225
225
226
226
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 ) ?;
238
231
Ok ( ( ) )
239
232
}
240
233
@@ -251,6 +244,26 @@ impl<'a> Generator<'a> {
251
244
}
252
245
}
253
246
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
+
254
267
pub fn main ( ) -> Result < ( ) , Box < dyn Error > > {
255
268
let blog = Generator :: new ( "site" , "posts" ) ?;
256
269
0 commit comments