@@ -8,7 +8,7 @@ use book::bookitem::BookItem;
8
8
use { utils, theme} ;
9
9
10
10
use std:: path:: { Path , PathBuf } ;
11
- use std:: fs:: File ;
11
+ use std:: fs:: { self , File } ;
12
12
use std:: error:: Error ;
13
13
use std:: io:: { self , Read , Write } ;
14
14
use std:: collections:: BTreeMap ;
@@ -50,7 +50,7 @@ impl Renderer for HtmlHandlebars {
50
50
51
51
// Check if dest directory exists
52
52
debug ! ( "[*]: Check if destination directory exists" ) ;
53
- if let Err ( _) = utils :: create_path ( book. get_dest ( ) ) {
53
+ if let Err ( _) = fs :: create_dir_all ( book. get_dest ( ) ) {
54
54
return Err ( Box :: new ( io:: Error :: new ( io:: ErrorKind :: Other , "Unexpected error when constructing destination path" ) ) )
55
55
}
56
56
@@ -159,42 +159,69 @@ impl Renderer for HtmlHandlebars {
159
159
160
160
debug ! ( "[*] Copy static files" ) ;
161
161
// JavaScript
162
- let mut js_file = try!( File :: create ( book. get_dest ( ) . join ( "book.js" ) ) ) ;
162
+ let mut js_file = if let Ok ( f) = File :: create ( book. get_dest ( ) . join ( "book.js" ) ) { f } else {
163
+ return Err ( Box :: new ( io:: Error :: new ( io:: ErrorKind :: Other , "Could not create book.js" ) ) )
164
+ } ;
163
165
try!( js_file. write_all ( & theme. js ) ) ;
164
166
165
167
// Css
166
- let mut css_file = try!( File :: create ( book. get_dest ( ) . join ( "book.css" ) ) ) ;
168
+ let mut css_file = if let Ok ( f) = File :: create ( book. get_dest ( ) . join ( "book.css" ) ) { f } else {
169
+ return Err ( Box :: new ( io:: Error :: new ( io:: ErrorKind :: Other , "Could not create book.css" ) ) )
170
+ } ;
167
171
try!( css_file. write_all ( & theme. css ) ) ;
168
172
169
173
// JQuery local fallback
170
- let mut jquery = try!( File :: create ( book. get_dest ( ) . join ( "jquery.js" ) ) ) ;
174
+ let mut jquery = if let Ok ( f) = File :: create ( book. get_dest ( ) . join ( "jquery.js" ) ) { f } else {
175
+ return Err ( Box :: new ( io:: Error :: new ( io:: ErrorKind :: Other , "Could not create jquery.js" ) ) )
176
+ } ;
171
177
try!( jquery. write_all ( & theme. jquery ) ) ;
172
178
179
+ // syntax highlighting
180
+ let mut highlight_css = if let Ok ( f) = File :: create ( book. get_dest ( ) . join ( "highlight.css" ) ) { f } else {
181
+ return Err ( Box :: new ( io:: Error :: new ( io:: ErrorKind :: Other , "Could not create highlight.css" ) ) )
182
+ } ;
183
+ try!( highlight_css. write_all ( & theme. highlight_css ) ) ;
184
+
185
+ let mut tomorrow_night_css = if let Ok ( f) = File :: create ( book. get_dest ( ) . join ( "tomorrow-night.css" ) ) { f } else {
186
+ return Err ( Box :: new ( io:: Error :: new ( io:: ErrorKind :: Other , "Could not create tomorrow-night.css" ) ) )
187
+ } ;
188
+ try!( tomorrow_night_css. write_all ( & theme. tomorrow_night_css ) ) ;
189
+
190
+ let mut highlight_js = if let Ok ( f) = File :: create ( book. get_dest ( ) . join ( "highlight.js" ) ) { f } else {
191
+ return Err ( Box :: new ( io:: Error :: new ( io:: ErrorKind :: Other , "Could not create highlight.js" ) ) )
192
+ } ;
193
+ try!( highlight_js. write_all ( & theme. highlight_js ) ) ;
194
+
173
195
// Font Awesome local fallback
174
- let mut font_awesome = try!( utils:: create_file ( & book. get_dest ( ) . join ( "_FontAwesome/css/font-awesome" ) . with_extension ( "css" ) ) ) ;
196
+ let mut font_awesome = if let Ok ( f) = utils:: create_file ( & book. get_dest ( ) . join ( "_FontAwesome/css/font-awesome.css" ) ) { f } else {
197
+ return Err ( Box :: new ( io:: Error :: new ( io:: ErrorKind :: Other , "Could not create font-awesome.css" ) ) )
198
+ } ;
175
199
try!( font_awesome. write_all ( theme:: FONT_AWESOME ) ) ;
176
- let mut font_awesome = try!( utils:: create_file ( & book. get_dest ( ) . join ( "_FontAwesome/fonts/fontawesome-webfont.eot" ) ) ) ;
200
+ let mut font_awesome = if let Ok ( f) = utils:: create_file ( & book. get_dest ( ) . join ( "_FontAwesome/fonts/fontawesome-webfont.eot" ) ) { f } else {
201
+ return Err ( Box :: new ( io:: Error :: new ( io:: ErrorKind :: Other , "Could not create fontawesome-webfont.eot" ) ) )
202
+ } ;
177
203
try!( font_awesome. write_all ( theme:: FONT_AWESOME_EOT ) ) ;
178
- let mut font_awesome = try!( utils:: create_file ( & book. get_dest ( ) . join ( "_FontAwesome/fonts/fontawesome-webfont.svg" ) ) ) ;
204
+ let mut font_awesome = if let Ok ( f) = utils:: create_file ( & book. get_dest ( ) . join ( "_FontAwesome/fonts/fontawesome-webfont.svg" ) ) { f } else {
205
+ return Err ( Box :: new ( io:: Error :: new ( io:: ErrorKind :: Other , "Could not create fontawesome-webfont.svg" ) ) )
206
+ } ;
179
207
try!( font_awesome. write_all ( theme:: FONT_AWESOME_SVG ) ) ;
180
- let mut font_awesome = try!( utils:: create_file ( & book. get_dest ( ) . join ( "_FontAwesome/fonts/fontawesome-webfont.ttf" ) ) ) ;
208
+ let mut font_awesome = if let Ok ( f) = utils:: create_file ( & book. get_dest ( ) . join ( "_FontAwesome/fonts/fontawesome-webfont.ttf" ) ) { f } else {
209
+ return Err ( Box :: new ( io:: Error :: new ( io:: ErrorKind :: Other , "Could not create fontawesome-webfont.ttf" ) ) )
210
+ } ;
181
211
try!( font_awesome. write_all ( theme:: FONT_AWESOME_TTF ) ) ;
182
- let mut font_awesome = try!( utils:: create_file ( & book. get_dest ( ) . join ( "_FontAwesome/fonts/fontawesome-webfont.woff" ) ) ) ;
212
+ let mut font_awesome = if let Ok ( f) = utils:: create_file ( & book. get_dest ( ) . join ( "_FontAwesome/fonts/fontawesome-webfont.woff" ) ) { f } else {
213
+ return Err ( Box :: new ( io:: Error :: new ( io:: ErrorKind :: Other , "Could not create fontawesome-webfont.woff" ) ) )
214
+ } ;
183
215
try!( font_awesome. write_all ( theme:: FONT_AWESOME_WOFF ) ) ;
184
- let mut font_awesome = try!( utils:: create_file ( & book. get_dest ( ) . join ( "_FontAwesome/fonts/fontawesome-webfont.woff2" ) ) ) ;
216
+ let mut font_awesome = if let Ok ( f) = utils:: create_file ( & book. get_dest ( ) . join ( "_FontAwesome/fonts/fontawesome-webfont.woff2" ) ) { f } else {
217
+ return Err ( Box :: new ( io:: Error :: new ( io:: ErrorKind :: Other , "Could not create fontawesome-webfont.woff2" ) ) )
218
+ } ;
185
219
try!( font_awesome. write_all ( theme:: FONT_AWESOME_WOFF2 ) ) ;
186
- let mut font_awesome = try!( utils:: create_file ( & book. get_dest ( ) . join ( "_FontAwesome/fonts/FontAwesome.ttf" ) ) ) ;
220
+ let mut font_awesome = if let Ok ( f) = utils:: create_file ( & book. get_dest ( ) . join ( "_FontAwesome/fonts/FontAwesome.ttf" ) ) { f } else {
221
+ return Err ( Box :: new ( io:: Error :: new ( io:: ErrorKind :: Other , "Could not create FontAwesome.ttf" ) ) )
222
+ } ;
187
223
try!( font_awesome. write_all ( theme:: FONT_AWESOME_TTF ) ) ;
188
224
189
- // syntax highlighting
190
- let mut highlight_css = try!( File :: create ( book. get_dest ( ) . join ( "highlight.css" ) ) ) ;
191
- try!( highlight_css. write_all ( & theme. highlight_css ) ) ;
192
- let mut tomorrow_night_css = try!( File :: create ( book. get_dest ( ) . join ( "tomorrow-night.css" ) ) ) ;
193
- try!( tomorrow_night_css. write_all ( & theme. tomorrow_night_css ) ) ;
194
- let mut highlight_js = try!( File :: create ( book. get_dest ( ) . join ( "highlight.js" ) ) ) ;
195
- try!( highlight_js. write_all ( & theme. highlight_js ) ) ;
196
-
197
-
198
225
// Copy all remaining files
199
226
try!( utils:: copy_files_except_ext ( book. get_src ( ) , book. get_dest ( ) , true , & [ "md" ] ) ) ;
200
227
0 commit comments