1
- use book:: { Book , BookItem , Chapter } ;
1
+ use book:: { Book , BookItem } ;
2
2
use config:: { Config , HtmlConfig , Playpen } ;
3
3
use errors:: * ;
4
4
use renderer:: html_handlebars:: helpers;
@@ -8,8 +8,7 @@ use utils;
8
8
9
9
use std:: collections:: BTreeMap ;
10
10
use std:: collections:: HashMap ;
11
- use std:: fs:: { self , File } ;
12
- use std:: io:: Read ;
11
+ use std:: fs;
13
12
use std:: path:: { Path , PathBuf } ;
14
13
15
14
use handlebars:: Handlebars ;
@@ -74,11 +73,21 @@ impl HtmlHandlebars {
74
73
let rendered = self . post_process ( rendered, & ctx. html_config . playpen ) ;
75
74
76
75
// Write to file
77
- debug ! ( "Creating {} ✓ " , filepath. display( ) ) ;
78
- utils:: fs:: write_file ( & ctx. destination , & filepath, & rendered. into_bytes ( ) ) ?;
76
+ debug ! ( "Creating {}" , filepath. display( ) ) ;
77
+ utils:: fs:: write_file ( & ctx. destination , & filepath, rendered. as_bytes ( ) ) ?;
79
78
80
79
if ctx. is_index {
81
- self . render_index ( ch, & ctx. destination ) ?;
80
+ ctx. data . insert ( "path" . to_owned ( ) , json ! ( "index.html" ) ) ;
81
+ ctx. data . insert ( "path_to_root" . to_owned ( ) , json ! ( "" ) ) ;
82
+ let rendered_index = ctx. handlebars . render ( "index" , & ctx. data ) ?;
83
+ let rendered_index =
84
+ self . post_process ( rendered_index, & ctx. html_config . playpen ) ;
85
+ debug ! ( "Creating index.html from {}" , path) ;
86
+ utils:: fs:: write_file (
87
+ & ctx. destination ,
88
+ "index.html" ,
89
+ rendered_index. as_bytes ( ) ,
90
+ ) ?;
82
91
}
83
92
}
84
93
_ => { }
@@ -87,34 +96,6 @@ impl HtmlHandlebars {
87
96
Ok ( ( ) )
88
97
}
89
98
90
- /// Create an index.html from the first element in SUMMARY.md
91
- fn render_index ( & self , ch : & Chapter , destination : & Path ) -> Result < ( ) > {
92
- debug ! ( "index.html" ) ;
93
-
94
- let mut content = String :: new ( ) ;
95
-
96
- File :: open ( destination. join ( & ch. path . with_extension ( "html" ) ) ) ?
97
- . read_to_string ( & mut content) ?;
98
-
99
- // This could cause a problem when someone displays
100
- // code containing <base href=...>
101
- // on the front page, however this case should be very very rare...
102
- content = content
103
- . lines ( )
104
- . filter ( |line| !line. contains ( "<base href=" ) )
105
- . collect :: < Vec < & str > > ( )
106
- . join ( "\n " ) ;
107
-
108
- utils:: fs:: write_file ( destination, "index.html" , content. as_bytes ( ) ) ?;
109
-
110
- debug ! (
111
- "Creating index.html from {} ✓" ,
112
- destination. join( & ch. path. with_extension( "html" ) ) . display( )
113
- ) ;
114
-
115
- Ok ( ( ) )
116
- }
117
-
118
99
#[ cfg_attr( feature = "cargo-clippy" , allow( let_and_return) ) ]
119
100
fn post_process ( & self , rendered : String , playpen_config : & Playpen ) -> String {
120
101
let rendered = build_header_links ( & rendered) ;
@@ -363,7 +344,7 @@ impl Renderer for HtmlHandlebars {
363
344
364
345
let rendered = self . post_process ( rendered, & html_config. playpen ) ;
365
346
366
- utils:: fs:: write_file ( & destination, "print.html" , & rendered. into_bytes ( ) ) ?;
347
+ utils:: fs:: write_file ( & destination, "print.html" , rendered. as_bytes ( ) ) ?;
367
348
debug ! ( "Creating print.html ✓" ) ;
368
349
369
350
debug ! ( "Copy static files" ) ;
0 commit comments