@@ -78,6 +78,10 @@ pub fn html_config_n_theme_dir_n_theme_n_handlebars(
7878 debug ! ( "Register the header handlebars template" ) ;
7979 handlebars. register_partial ( "header" , String :: from_utf8 ( theme. header . clone ( ) ) ?) ?;
8080
81+ debug ! ( "Register the toc handlebars template" ) ;
82+ handlebars. register_template_string ( "toc_js" , String :: from_utf8 ( theme. toc_js . clone ( ) ) ?) ?;
83+ handlebars. register_template_string ( "toc_html" , String :: from_utf8 ( theme. toc_html . clone ( ) ) ?) ?;
84+
8185 debug ! ( "Register handlebars helpers" ) ;
8286 RENDERER . register_hbs_helpers ( & mut handlebars, & html_config) ;
8387
@@ -200,6 +204,18 @@ impl HtmlHbsState {
200204 debug ! ( "Created print.html ✓" ) ;
201205 }
202206
207+ debug ! ( "Render toc" ) ;
208+ {
209+ let rendered_toc = handlebars. render ( "toc_js" , & data) ?;
210+ utils:: fs:: write_file ( destination, "toc.js" , rendered_toc. as_bytes ( ) ) ?;
211+ debug ! ( "Creating toc.js ✓" ) ;
212+ data. insert ( "is_toc_html" . to_owned ( ) , json ! ( true ) ) ;
213+ let rendered_toc = handlebars. render ( "toc_html" , & data) ?;
214+ utils:: fs:: write_file ( destination, "toc.html" , rendered_toc. as_bytes ( ) ) ?;
215+ debug ! ( "Creating toc.html ✓" ) ;
216+ data. remove ( "is_toc_html" ) ;
217+ }
218+
203219 // Render search index
204220 let search = html_config. search . clone ( ) . unwrap_or_default ( ) ;
205221 if search. enable {
0 commit comments