@@ -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.
0 commit comments