@@ -181,42 +181,34 @@ pub(super) fn write_shared(
181
181
cx. write_shared ( SharedResource :: InvocationSpecific { basename : p } , content, & options. emit )
182
182
} ;
183
183
184
- fn add_background_image_to_css (
185
- cx : & Context < ' _ > ,
186
- css : & mut String ,
187
- rule : & str ,
188
- file : & ' static str ,
189
- ) {
190
- css. push_str ( & format ! (
191
- "{} {{ background-image: url({}); }}" ,
192
- rule,
193
- SharedResource :: ToolchainSpecific { basename: file }
184
+ // Given "foo.svg", return e.g. "url(\"foo1.58.0.svg\")"
185
+ fn ver_url ( cx : & Context < ' _ > , basename : & ' static str ) -> String {
186
+ format ! (
187
+ "url(\" {}\" )" ,
188
+ SharedResource :: ToolchainSpecific { basename }
194
189
. path( cx)
195
190
. file_name( )
196
191
. unwrap( )
197
192
. to_str( )
198
193
. unwrap( )
199
- ) )
194
+ )
200
195
}
201
196
202
- // Add all the static files. These may already exist, but we just
203
- // overwrite them anyway to make sure that they're fresh and up-to-date.
204
- let mut rustdoc_css = static_files :: RUSTDOC_CSS . to_owned ( ) ;
205
- add_background_image_to_css (
206
- cx ,
207
- & mut rustdoc_css ,
208
- "details.undocumented[open] > summary::before, \
209
- details.rustdoc-toggle[open] > summary::before, \
210
- details.rustdoc-toggle[open] > summary.hideme::before" ,
211
- "toggle-minus.svg" ,
212
- ) ;
213
- add_background_image_to_css (
197
+ // We use the AUTOREPLACE mechanism to inject into our static JS and CSS certain
198
+ // values that are only known at doc build time. Since this mechanism is somewhat
199
+ // surprising when reading the code, please limit it to rustdoc.css.
200
+ write_minify (
201
+ "rustdoc.css" ,
202
+ static_files :: RUSTDOC_CSS
203
+ . replace (
204
+ "/* AUTOREPLACE: */url( \" toggle-minus.svg \" )" ,
205
+ & ver_url ( cx , "toggle-minus.svg" ) ,
206
+ )
207
+ . replace ( "/* AUTOREPLACE: */url( \" toggle-plus.svg \" )" , & ver_url ( cx , "toggle-plus.svg" ) )
208
+ . replace ( "/* AUTOREPLACE: */url( \" down-arrow.svg \" )" , & ver_url ( cx , "down-arrow.svg" ) ) ,
214
209
cx,
215
- & mut rustdoc_css,
216
- "details.undocumented > summary::before, details.rustdoc-toggle > summary::before" ,
217
- "toggle-plus.svg" ,
218
- ) ;
219
- write_minify ( "rustdoc.css" , rustdoc_css, cx, options) ?;
210
+ options,
211
+ ) ?;
220
212
221
213
// Add all the static files. These may already exist, but we just
222
214
// overwrite them anyway to make sure that they're fresh and up-to-date.
@@ -228,12 +220,12 @@ pub(super) fn write_shared(
228
220
let mut themes: FxHashSet < String > = FxHashSet :: default ( ) ;
229
221
230
222
for entry in & cx. shared . style_files {
231
- let theme = try_none ! ( try_none! ( entry. path . file_stem ( ) , & entry . path ) . to_str ( ) , & entry . path ) ;
223
+ let theme = entry. basename ( ) ? ;
232
224
let extension =
233
225
try_none ! ( try_none!( entry. path. extension( ) , & entry. path) . to_str( ) , & entry. path) ;
234
226
235
227
// Handle the official themes
236
- match theme {
228
+ match theme. as_str ( ) {
237
229
"light" => write_minify ( "light.css" , static_files:: themes:: LIGHT , cx, options) ?,
238
230
"dark" => write_minify ( "dark.css" , static_files:: themes:: DARK , cx, options) ?,
239
231
"ayu" => write_minify ( "ayu.css" , static_files:: themes:: AYU , cx, options) ?,
@@ -265,45 +257,15 @@ pub(super) fn write_shared(
265
257
let mut themes: Vec < & String > = themes. iter ( ) . collect ( ) ;
266
258
themes. sort ( ) ;
267
259
268
- // FIXME: this should probably not be a toolchain file since it depends on `--theme`.
269
- // But it seems a shame to copy it over and over when it's almost always the same.
270
- // Maybe we can change the representation to move this out of main.js?
271
- write_minify (
272
- "main.js" ,
273
- static_files:: MAIN_JS
274
- . replace (
275
- "/* INSERT THEMES HERE */" ,
276
- & format ! ( " = {}" , serde_json:: to_string( & themes) . unwrap( ) ) ,
277
- )
278
- . replace (
279
- "/* INSERT RUSTDOC_VERSION HERE */" ,
280
- & format ! (
281
- "rustdoc {}" ,
282
- rustc_interface:: util:: version_str( ) . unwrap_or( "unknown version" )
283
- ) ,
284
- ) ,
285
- cx,
286
- options,
287
- ) ?;
260
+ write_minify ( "main.js" , static_files:: MAIN_JS , cx, options) ?;
288
261
write_minify ( "search.js" , static_files:: SEARCH_JS , cx, options) ?;
289
262
write_minify ( "settings.js" , static_files:: SETTINGS_JS , cx, options) ?;
290
263
291
264
if cx. include_sources {
292
265
write_minify ( "source-script.js" , static_files:: sidebar:: SOURCE_SCRIPT , cx, options) ?;
293
266
}
294
267
295
- {
296
- write_minify (
297
- "storage.js" ,
298
- format ! (
299
- "var resourcesSuffix = \" {}\" ;{}" ,
300
- cx. shared. resource_suffix,
301
- static_files:: STORAGE_JS
302
- ) ,
303
- cx,
304
- options,
305
- ) ?;
306
- }
268
+ write_minify ( "storage.js" , static_files:: STORAGE_JS , cx, options) ?;
307
269
308
270
if cx. shared . layout . scrape_examples_extension {
309
271
cx. write_minify (
0 commit comments