@@ -181,42 +181,34 @@ pub(super) fn write_shared(
181181 cx. write_shared ( SharedResource :: InvocationSpecific { basename : p } , content, & options. emit )
182182 } ;
183183
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 }
194189 . path( cx)
195190 . file_name( )
196191 . unwrap( )
197192 . to_str( )
198193 . unwrap( )
199- ) )
194+ )
200195 }
201196
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" ) ) ,
214209 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+ ) ?;
220212
221213 // Add all the static files. These may already exist, but we just
222214 // overwrite them anyway to make sure that they're fresh and up-to-date.
@@ -228,12 +220,12 @@ pub(super) fn write_shared(
228220 let mut themes: FxHashSet < String > = FxHashSet :: default ( ) ;
229221
230222 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 ( ) ? ;
232224 let extension =
233225 try_none ! ( try_none!( entry. path. extension( ) , & entry. path) . to_str( ) , & entry. path) ;
234226
235227 // Handle the official themes
236- match theme {
228+ match theme. as_str ( ) {
237229 "light" => write_minify ( "light.css" , static_files:: themes:: LIGHT , cx, options) ?,
238230 "dark" => write_minify ( "dark.css" , static_files:: themes:: DARK , cx, options) ?,
239231 "ayu" => write_minify ( "ayu.css" , static_files:: themes:: AYU , cx, options) ?,
@@ -265,45 +257,15 @@ pub(super) fn write_shared(
265257 let mut themes: Vec < & String > = themes. iter ( ) . collect ( ) ;
266258 themes. sort ( ) ;
267259
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) ?;
288261 write_minify ( "search.js" , static_files:: SEARCH_JS , cx, options) ?;
289262 write_minify ( "settings.js" , static_files:: SETTINGS_JS , cx, options) ?;
290263
291264 if cx. include_sources {
292265 write_minify ( "source-script.js" , static_files:: sidebar:: SOURCE_SCRIPT , cx, options) ?;
293266 }
294267
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) ?;
307269
308270 if cx. shared . layout . scrape_examples_extension {
309271 cx. write_minify (
0 commit comments