@@ -18,7 +18,6 @@ struct Generator<'a> {
18
18
handlebars : Handlebars < ' a > ,
19
19
blogs : Vec < Blog > ,
20
20
out_directory : PathBuf ,
21
- file_url : String ,
22
21
}
23
22
24
23
#[ derive( Debug , Serialize ) ]
@@ -58,28 +57,29 @@ impl<'a> Generator<'a> {
58
57
handlebars. register_templates_directory ( ".hbs" , "templates" ) ?;
59
58
handlebars. register_helper ( "month_name" , Box :: new ( hb_month_name_helper) ) ;
60
59
61
- let file_url = format ! (
62
- "file:///{}/" ,
63
- out_directory
64
- . as_ref( )
65
- . canonicalize( )
66
- . unwrap_or_else( |_| out_directory. as_ref( ) . to_owned( ) )
67
- . display( )
68
- . to_string( )
69
- . trim_start_matches( '/' )
70
- . replace( ' ' , "%20" )
71
- . replace( "\\ \\ ?\\ " , "" )
72
- . replace( std:: path:: MAIN_SEPARATOR , "/" )
73
- ) ;
74
-
75
60
Ok ( Generator {
76
61
handlebars,
77
62
blogs : crate :: blogs:: load ( posts_directory. as_ref ( ) ) ?,
78
63
out_directory : out_directory. as_ref ( ) . into ( ) ,
79
- file_url,
80
64
} )
81
65
}
82
66
67
+ fn file_url ( & self , path : & Path ) -> String {
68
+ format ! (
69
+ "file:///{}/{}" ,
70
+ self . out_directory
71
+ . canonicalize( )
72
+ . unwrap_or_else( |_| self . out_directory. to_owned( ) )
73
+ . display( )
74
+ . to_string( )
75
+ . trim_start_matches( '/' )
76
+ . replace( ' ' , "%20" )
77
+ . replace( "\\ \\ ?\\ " , "" ) ,
78
+ path. display( )
79
+ )
80
+ . replace ( std:: path:: MAIN_SEPARATOR , "/" )
81
+ }
82
+
83
83
fn render ( & self ) -> Result < ( ) , Box < dyn Error > > {
84
84
// make sure our output directory exists
85
85
fs:: create_dir_all ( & self . out_directory ) ?;
@@ -121,15 +121,15 @@ impl<'a> Generator<'a> {
121
121
122
122
let path = self . render_index ( blog) ?;
123
123
124
- println ! ( "{}: {}{} " , blog. title( ) , self . file_url, path . display ( ) ) ;
124
+ println ! ( "{}: {}" , blog. title( ) , self . file_url( & path ) ) ;
125
125
126
126
self . render_feed ( blog) ?;
127
127
self . render_releases_feed ( blog) ?;
128
128
129
129
for ( i, post) in blog. posts ( ) . iter ( ) . enumerate ( ) {
130
130
let path = self . render_post ( blog, post) ?;
131
131
if i == 0 {
132
- println ! ( "└─ Latest post: {}{} \n " , self . file_url, path . display ( ) ) ;
132
+ println ! ( "└─ Latest post: {}\n " , self . file_url( & path ) ) ;
133
133
}
134
134
}
135
135
0 commit comments