@@ -9,7 +9,6 @@ use sass_rs::{compile_file, Options};
9
9
use serde_derive:: Serialize ;
10
10
use serde_json:: json;
11
11
use std:: convert:: AsRef ;
12
- use std:: error:: Error ;
13
12
use std:: fs:: { self , File } ;
14
13
use std:: io:: { self , Write } ;
15
14
use std:: path:: { Path , PathBuf } ;
@@ -51,7 +50,7 @@ impl<'a> Generator<'a> {
51
50
fn new (
52
51
out_directory : impl AsRef < Path > ,
53
52
posts_directory : impl AsRef < Path > ,
54
- ) -> Result < Self , Box < dyn Error > > {
53
+ ) -> eyre :: Result < Self > {
55
54
let mut handlebars = Handlebars :: new ( ) ;
56
55
handlebars. set_strict_mode ( true ) ;
57
56
handlebars. register_templates_directory ( ".hbs" , "templates" ) ?;
@@ -80,7 +79,7 @@ impl<'a> Generator<'a> {
80
79
. replace ( std:: path:: MAIN_SEPARATOR , "/" )
81
80
}
82
81
83
- fn render ( & self ) -> Result < ( ) , Box < dyn Error > > {
82
+ fn render ( & self ) -> eyre :: Result < ( ) > {
84
83
// make sure our output directory exists
85
84
fs:: create_dir_all ( & self . out_directory ) ?;
86
85
@@ -116,7 +115,7 @@ impl<'a> Generator<'a> {
116
115
fs:: write ( "./static/styles/vendor.css" , & concatted) . expect ( "couldn't write vendor css" ) ;
117
116
}
118
117
119
- fn render_blog ( & self , blog : & Blog ) -> Result < ( ) , Box < dyn Error > > {
118
+ fn render_blog ( & self , blog : & Blog ) -> eyre :: Result < ( ) > {
120
119
std:: fs:: create_dir_all ( self . out_directory . join ( blog. prefix ( ) ) ) ?;
121
120
122
121
let path = self . render_index ( blog) ?;
@@ -136,7 +135,7 @@ impl<'a> Generator<'a> {
136
135
Ok ( ( ) )
137
136
}
138
137
139
- fn render_index ( & self , blog : & Blog ) -> Result < PathBuf , Box < dyn Error > > {
138
+ fn render_index ( & self , blog : & Blog ) -> eyre :: Result < PathBuf > {
140
139
let other_blogs: Vec < _ > = self
141
140
. blogs
142
141
. iter ( )
@@ -161,7 +160,7 @@ impl<'a> Generator<'a> {
161
160
Ok ( path)
162
161
}
163
162
164
- fn render_post ( & self , blog : & Blog , post : & Post ) -> Result < PathBuf , Box < dyn Error > > {
163
+ fn render_post ( & self , blog : & Blog , post : & Post ) -> eyre :: Result < PathBuf > {
165
164
let path = blog
166
165
. prefix ( )
167
166
. join ( format ! ( "{:04}" , & post. year) )
@@ -186,7 +185,7 @@ impl<'a> Generator<'a> {
186
185
Ok ( path)
187
186
}
188
187
189
- fn render_feed ( & self , blog : & Blog ) -> Result < ( ) , Box < dyn Error > > {
188
+ fn render_feed ( & self , blog : & Blog ) -> eyre :: Result < ( ) > {
190
189
let posts: Vec < _ > = blog. posts ( ) . iter ( ) . take ( 10 ) . collect ( ) ;
191
190
let data = json ! ( {
192
191
"blog" : blog,
@@ -198,7 +197,7 @@ impl<'a> Generator<'a> {
198
197
Ok ( ( ) )
199
198
}
200
199
201
- fn render_releases_feed ( & self , blog : & Blog ) -> Result < ( ) , Box < dyn Error > > {
200
+ fn render_releases_feed ( & self , blog : & Blog ) -> eyre :: Result < ( ) > {
202
201
let posts = blog. posts ( ) . iter ( ) . cloned ( ) . collect :: < Vec < _ > > ( ) ;
203
202
let is_released: Vec < & Post > = posts. iter ( ) . filter ( |post| post. release ) . collect ( ) ;
204
203
let releases: Vec < ReleasePost > = is_released
@@ -223,7 +222,7 @@ impl<'a> Generator<'a> {
223
222
Ok ( ( ) )
224
223
}
225
224
226
- fn copy_static_files ( & self ) -> Result < ( ) , Box < dyn Error > > {
225
+ fn copy_static_files ( & self ) -> eyre :: Result < ( ) > {
227
226
copy_dir ( "static/fonts" , & self . out_directory ) ?;
228
227
copy_dir ( "static/images" , & self . out_directory ) ?;
229
228
copy_dir ( "static/styles" , & self . out_directory ) ?;
@@ -236,7 +235,7 @@ impl<'a> Generator<'a> {
236
235
name : impl AsRef < Path > ,
237
236
template : & str ,
238
237
data : serde_json:: Value ,
239
- ) -> Result < ( ) , Box < dyn Error > > {
238
+ ) -> eyre :: Result < ( ) > {
240
239
let out_file = self . out_directory . join ( name. as_ref ( ) ) ;
241
240
let file = File :: create ( out_file) ?;
242
241
self . handlebars . render_to_write ( template, & data, file) ?;
@@ -264,7 +263,7 @@ fn copy_dir(source: impl AsRef<Path>, dest: impl AsRef<Path>) -> Result<(), io::
264
263
copy_inner ( source, & dest)
265
264
}
266
265
267
- pub fn main ( ) -> Result < ( ) , Box < dyn Error > > {
266
+ pub fn main ( ) -> eyre :: Result < ( ) > {
268
267
let blog = Generator :: new ( "site" , "posts" ) ?;
269
268
270
269
blog. render ( ) ?;
0 commit comments