@@ -26,6 +26,7 @@ pub struct Page<'a> {
2626 pub title : & ' a str ,
2727 pub css_class : & ' a str ,
2828 pub root_path : & ' a str ,
29+ pub static_root_path : Option < & ' a str > ,
2930 pub description : & ' a str ,
3031 pub keywords : & ' a str ,
3132 pub resource_suffix : & ' a str ,
@@ -36,6 +37,7 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
3637 css_file_extension : bool , themes : & [ PathBuf ] , extra_scripts : & [ & str ] )
3738 -> io:: Result < ( ) >
3839{
40+ let static_root_path = page. static_root_path . unwrap_or ( page. root_path ) ;
3941 write ! ( dst,
4042"<!DOCTYPE html>\
4143 <html lang=\" en\" >\
@@ -46,20 +48,20 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
4648 <meta name=\" description\" content=\" {description}\" >\
4749 <meta name=\" keywords\" content=\" {keywords}\" >\
4850 <title>{title}</title>\
49- <link rel=\" stylesheet\" type=\" text/css\" href=\" {root_path }normalize{suffix}.css\" >\
50- <link rel=\" stylesheet\" type=\" text/css\" href=\" {root_path }rustdoc{suffix}.css\" \
51+ <link rel=\" stylesheet\" type=\" text/css\" href=\" {static_root_path }normalize{suffix}.css\" >\
52+ <link rel=\" stylesheet\" type=\" text/css\" href=\" {static_root_path }rustdoc{suffix}.css\" \
5153 id=\" mainThemeStyle\" >\
5254 {themes}\
53- <link rel=\" stylesheet\" type=\" text/css\" href=\" {root_path }dark{suffix}.css\" >\
54- <link rel=\" stylesheet\" type=\" text/css\" href=\" {root_path }light{suffix}.css\" \
55+ <link rel=\" stylesheet\" type=\" text/css\" href=\" {static_root_path }dark{suffix}.css\" >\
56+ <link rel=\" stylesheet\" type=\" text/css\" href=\" {static_root_path }light{suffix}.css\" \
5557 id=\" themeStyle\" >\
56- <script src=\" {root_path }storage{suffix}.js\" ></script>\
57- <noscript><link rel=\" stylesheet\" href=\" {root_path }noscript{suffix}.css\" ></noscript>\
58+ <script src=\" {static_root_path }storage{suffix}.js\" ></script>\
59+ <noscript><link rel=\" stylesheet\" href=\" {static_root_path }noscript{suffix}.css\" ></noscript>\
5860 {css_extension}\
5961 {favicon}\
6062 {in_header}\
6163 <style type=\" text/css\" >\
62- #crate-search{{background-image:url(\" {root_path }down-arrow{suffix}.svg\" );}}\
64+ #crate-search{{background-image:url(\" {static_root_path }down-arrow{suffix}.svg\" );}}\
6365 </style>\
6466 </head>\
6567 <body class=\" rustdoc {css_class}\" >\
@@ -77,11 +79,13 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
7779 </nav>\
7880 <div class=\" theme-picker\" >\
7981 <button id=\" theme-picker\" aria-label=\" Pick another theme!\" >\
80- <img src=\" {root_path}brush{suffix}.svg\" width=\" 18\" alt=\" Pick another theme!\" >\
82+ <img src=\" {static_root_path}brush{suffix}.svg\" \
83+ width=\" 18\" \
84+ alt=\" Pick another theme!\" >\
8185 </button>\
8286 <div id=\" theme-choices\" ></div>\
8387 </div>\
84- <script src=\" {root_path }theme{suffix}.js\" ></script>\
88+ <script src=\" {static_root_path }theme{suffix}.js\" ></script>\
8589 <nav class=\" sub\" >\
8690 <form class=\" search-form js-only\" >\
8791 <div class=\" search-container\" >\
@@ -96,7 +100,9 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
96100 type=\" search\" >\
97101 </div>\
98102 <a id=\" settings-menu\" href=\" {root_path}settings.html\" >\
99- <img src=\" {root_path}wheel{suffix}.svg\" width=\" 18\" alt=\" Change settings\" >\
103+ <img src=\" {static_root_path}wheel{suffix}.svg\" \
104+ width=\" 18\" \
105+ alt=\" Change settings\" >\
100106 </a>\
101107 </div>\
102108 </form>\
@@ -157,19 +163,22 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
157163 window.currentCrate = \" {krate}\" ;\
158164 </script>\
159165 <script src=\" {root_path}aliases.js\" ></script>\
160- <script src=\" {root_path }main{suffix}.js\" ></script>\
166+ <script src=\" {static_root_path }main{suffix}.js\" ></script>\
161167 {extra_scripts}\
162168 <script defer src=\" {root_path}search-index.js\" ></script>\
163169 </body>\
164170 </html>",
165171 css_extension = if css_file_extension {
166- format!( "<link rel=\" stylesheet\" type=\" text/css\" href=\" {root_path}theme{suffix}.css\" >" ,
167- root_path = page. root_path,
172+ format!( "<link rel=\" stylesheet\" \
173+ type=\" text/css\" \
174+ href=\" {static_root_path}theme{suffix}.css\" >",
175+ static_root_path = static_root_path,
168176 suffix=page. resource_suffix)
169177 } else {
170178 String :: new( )
171179 } ,
172180 content = * t,
181+ static_root_path = static_root_path,
173182 root_path = page. root_path,
174183 css_class = page. css_class,
175184 logo = if layout. logo. is_empty( ) {
@@ -197,11 +206,13 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
197206 . filter_map( |t| t. file_stem( ) )
198207 . filter_map( |t| t. to_str( ) )
199208 . map( |t| format!( r#"<link rel="stylesheet" type="text/css" href="{}{}{}.css">"# ,
200- page . root_path ,
209+ static_root_path ,
201210 t,
202211 page. resource_suffix) )
203212 . collect:: <String >( ) ,
204213 suffix=page. resource_suffix,
214+ // TODO: break out a separate `static_extra_scripts` that uses `static_root_path` instead,
215+ // then leave `source-files.js` here and move `source-script.js` to the static version
205216 extra_scripts=extra_scripts. iter( ) . map( |e| {
206217 format!( "<script src=\" {root_path}{extra_script}.js\" ></script>" ,
207218 root_path=page. root_path,
0 commit comments