@@ -187,14 +187,22 @@ impl Renderer for HtmlHandlebars {
187187 book. write_file ( "_FontAwesome/fonts/fontawesome-webfont.woff2" , theme:: FONT_AWESOME_WOFF2 ) ?;
188188 book. write_file ( "_FontAwesome/fonts/FontAwesome.ttf" , theme:: FONT_AWESOME_TTF ) ?;
189189
190- for style in book. get_additional_css ( ) {
190+ for custom_file in book. get_additional_css ( )
191+ . iter ( )
192+ . chain ( book. get_additional_js ( ) . iter ( ) ) {
191193 let mut data = Vec :: new ( ) ;
192- let mut f = File :: open ( style ) ?;
194+ let mut f = File :: open ( custom_file ) ?;
193195 f. read_to_end ( & mut data) ?;
194196
195- let name = match style . strip_prefix ( book. get_root ( ) ) {
197+ let name = match custom_file . strip_prefix ( book. get_root ( ) ) {
196198 Ok ( p) => p. to_str ( ) . expect ( "Could not convert to str" ) ,
197- Err ( _) => style. file_name ( ) . expect ( "File has a file name" ) . to_str ( ) . expect ( "Could not convert to str" ) ,
199+ Err ( _) => {
200+ custom_file
201+ . file_name ( )
202+ . expect ( "File has a file name" )
203+ . to_str ( )
204+ . expect ( "Could not convert to str" )
205+ }
198206 } ;
199207
200208 book. write_file ( name, & data) ?;
@@ -240,6 +248,18 @@ fn make_data(book: &MDBook) -> Result<serde_json::Map<String, serde_json::Value>
240248 data. insert ( "additional_css" . to_owned ( ) , json ! ( css) ) ;
241249 }
242250
251+ // Add check to see if there is an additional script
252+ if book. has_additional_js ( ) {
253+ let mut js = Vec :: new ( ) ;
254+ for script in book. get_additional_js ( ) {
255+ match script. strip_prefix ( book. get_root ( ) ) {
256+ Ok ( p) => js. push ( p. to_str ( ) . expect ( "Could not convert to str" ) ) ,
257+ Err ( _) => js. push ( script. file_name ( ) . expect ( "File has a file name" ) . to_str ( ) . expect ( "Could not convert to str" ) ) ,
258+ }
259+ }
260+ data. insert ( "additional_js" . to_owned ( ) , json ! ( js) ) ;
261+ }
262+
243263 let mut chapters = vec ! [ ] ;
244264
245265 for item in book. iter ( ) {
0 commit comments