1- use crate :: web:: page:: TemplateData ;
1+ use crate :: web:: page:: templates:: { Head , Vendored , Body , Topbar } ;
2+ use crate :: web:: rustdoc:: RustdocPage ;
3+ use askama:: Template ;
24use lol_html:: element;
35use lol_html:: errors:: RewritingError ;
4- use tera:: Context ;
56
67/// Rewrite a rustdoc page to have the docs.rs topbar
78///
@@ -12,17 +13,15 @@ use tera::Context;
1213pub ( crate ) fn rewrite_lol (
1314 html : & [ u8 ] ,
1415 max_allowed_memory_usage : usize ,
15- ctx : Context ,
16- templates : & TemplateData ,
16+ data : & RustdocPage ,
1717) -> Result < Vec < u8 > , RewritingError > {
1818 use lol_html:: html_content:: { ContentType , Element } ;
1919 use lol_html:: { HtmlRewriter , MemorySettings , Settings } ;
2020
21- let templates = & templates. templates ;
22- let tera_head = templates. render ( "rustdoc/head.html" , & ctx) . unwrap ( ) ;
23- let tera_vendored_css = templates. render ( "rustdoc/vendored.html" , & ctx) . unwrap ( ) ;
24- let tera_body = templates. render ( "rustdoc/body.html" , & ctx) . unwrap ( ) ;
25- let tera_rustdoc_topbar = templates. render ( "rustdoc/topbar.html" , & ctx) . unwrap ( ) ;
21+ let head_html = Head :: new ( data) . render ( ) . unwrap ( ) ;
22+ let vendored_html = Vendored :: new ( data) . render ( ) . unwrap ( ) ;
23+ let body_html = Body :: new ( data) . render ( ) . unwrap ( ) ;
24+ let topbar_html = Topbar :: new ( data) . render ( ) . unwrap ( ) ;
2625
2726 // Before: <body> ... rustdoc content ... </body>
2827 // After:
@@ -46,12 +45,12 @@ pub(crate) fn rewrite_lol(
4645 rustdoc_body_class. set_attribute ( "tabindex" , "-1" ) ?;
4746 // Change the `body` to a `div`
4847 rustdoc_body_class. set_tag_name ( "div" ) ?;
49- // Prepend the tera content
50- rustdoc_body_class. prepend ( & tera_body , ContentType :: Html ) ;
48+ // Prepend the askama content
49+ rustdoc_body_class. prepend ( & body_html , ContentType :: Html ) ;
5150 // Wrap the transformed body and topbar into a <body> element
5251 rustdoc_body_class. before ( r#"<body class="rustdoc-page">"# , ContentType :: Html ) ;
5352 // Insert the topbar outside of the rustdoc div
54- rustdoc_body_class. before ( & tera_rustdoc_topbar , ContentType :: Html ) ;
53+ rustdoc_body_class. before ( & topbar_html , ContentType :: Html ) ;
5554 // Finalize body with </body>
5655 rustdoc_body_class. after ( "</body>" , ContentType :: Html ) ;
5756
@@ -62,7 +61,7 @@ pub(crate) fn rewrite_lol(
6261 element_content_handlers : vec ! [
6362 // Append `style.css` stylesheet after all head elements.
6463 element!( "head" , |head: & mut Element | {
65- head. append( & tera_head , ContentType :: Html ) ;
64+ head. append( & head_html , ContentType :: Html ) ;
6665 Ok ( ( ) )
6766 } ) ,
6867 element!( "body" , body_handler) ,
@@ -81,7 +80,7 @@ pub(crate) fn rewrite_lol(
8180 element!(
8281 "link[rel='stylesheet'][href*='rustdoc-']" ,
8382 |rustdoc_css: & mut Element | {
84- rustdoc_css. before( & tera_vendored_css , ContentType :: Html ) ;
83+ rustdoc_css. before( & vendored_html , ContentType :: Html ) ;
8584 Ok ( ( ) )
8685 }
8786 ) ,
0 commit comments