@@ -26,6 +26,7 @@ pub struct Page<'a> {
26
26
pub title : & ' a str ,
27
27
pub css_class : & ' a str ,
28
28
pub root_path : & ' a str ,
29
+ pub static_root_path : Option < & ' a str > ,
29
30
pub description : & ' a str ,
30
31
pub keywords : & ' a str ,
31
32
pub resource_suffix : & ' a str ,
@@ -36,6 +37,7 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
36
37
css_file_extension : bool , themes : & [ PathBuf ] , extra_scripts : & [ & str ] )
37
38
-> io:: Result < ( ) >
38
39
{
40
+ let static_root_path = page. static_root_path . unwrap_or ( page. root_path ) ;
39
41
write ! ( dst,
40
42
"<!DOCTYPE html>\
41
43
<html lang=\" en\" >\
@@ -46,20 +48,20 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
46
48
<meta name=\" description\" content=\" {description}\" >\
47
49
<meta name=\" keywords\" content=\" {keywords}\" >\
48
50
<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\" \
51
53
id=\" mainThemeStyle\" >\
52
54
{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\" \
55
57
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>\
58
60
{css_extension}\
59
61
{favicon}\
60
62
{in_header}\
61
63
<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\" );}}\
63
65
</style>\
64
66
</head>\
65
67
<body class=\" rustdoc {css_class}\" >\
@@ -77,11 +79,13 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
77
79
</nav>\
78
80
<div class=\" theme-picker\" >\
79
81
<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!\" >\
81
85
</button>\
82
86
<div id=\" theme-choices\" ></div>\
83
87
</div>\
84
- <script src=\" {root_path }theme{suffix}.js\" ></script>\
88
+ <script src=\" {static_root_path }theme{suffix}.js\" ></script>\
85
89
<nav class=\" sub\" >\
86
90
<form class=\" search-form js-only\" >\
87
91
<div class=\" search-container\" >\
@@ -96,7 +100,9 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
96
100
type=\" search\" >\
97
101
</div>\
98
102
<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\" >\
100
106
</a>\
101
107
</div>\
102
108
</form>\
@@ -157,19 +163,22 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
157
163
window.currentCrate = \" {krate}\" ;\
158
164
</script>\
159
165
<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>\
161
167
{extra_scripts}\
162
168
<script defer src=\" {root_path}search-index.js\" ></script>\
163
169
</body>\
164
170
</html>",
165
171
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,
168
176
suffix=page. resource_suffix)
169
177
} else {
170
178
String :: new( )
171
179
} ,
172
180
content = * t,
181
+ static_root_path = static_root_path,
173
182
root_path = page. root_path,
174
183
css_class = page. css_class,
175
184
logo = if layout. logo. is_empty( ) {
@@ -197,11 +206,13 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
197
206
. filter_map( |t| t. file_stem( ) )
198
207
. filter_map( |t| t. to_str( ) )
199
208
. map( |t| format!( r#"<link rel="stylesheet" type="text/css" href="{}{}{}.css">"# ,
200
- page . root_path ,
209
+ static_root_path ,
201
210
t,
202
211
page. resource_suffix) )
203
212
. collect:: <String >( ) ,
204
213
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
205
216
extra_scripts=extra_scripts. iter( ) . map( |e| {
206
217
format!( "<script src=\" {root_path}{extra_script}.js\" ></script>" ,
207
218
root_path=page. root_path,
0 commit comments