@@ -181,18 +181,26 @@ pub(super) fn write_shared(
181
181
cx. write_shared ( SharedResource :: InvocationSpecific { basename : p } , content, & options. emit )
182
182
} ;
183
183
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 }
189
- . path( cx)
190
- . file_name( )
191
- . unwrap( )
192
- . to_str( )
193
- . unwrap( )
194
- )
195
- }
184
+ // Given "foo.svg", either include it directly in the CSS as a data URL,
185
+ // or link to it, depending on the options.
186
+ let css_icon_url = |basename : & ' static str , icon : & [ u8 ] | -> String {
187
+ if basename. ends_with ( ".svg" ) && options. enable_minification {
188
+ use percent_encoding:: { utf8_percent_encode, AsciiSet , CONTROLS } ;
189
+ const DATA_URI : & AsciiSet = & CONTROLS . add ( b'\'' ) . add ( b'#' ) . add ( b'?' ) ;
190
+ let icn = utf8_percent_encode ( std:: str:: from_utf8 ( icon) . unwrap ( ) , DATA_URI ) ;
191
+ format ! ( "url('data:image/svg+xml,{}')" , icn, )
192
+ } else {
193
+ format ! (
194
+ "url(\" {}\" )" ,
195
+ SharedResource :: ToolchainSpecific { basename }
196
+ . path( cx)
197
+ . file_name( )
198
+ . unwrap( )
199
+ . to_str( )
200
+ . unwrap( )
201
+ )
202
+ }
203
+ } ;
196
204
197
205
// We use the AUTOREPLACE mechanism to inject into our static JS and CSS certain
198
206
// values that are only known at doc build time. Since this mechanism is somewhat
@@ -202,10 +210,16 @@ pub(super) fn write_shared(
202
210
static_files:: RUSTDOC_CSS
203
211
. replace (
204
212
"/* AUTOREPLACE: */url(\" toggle-minus.svg\" )" ,
205
- & ver_url ( cx, "toggle-minus.svg" ) ,
213
+ & css_icon_url ( "toggle-minus.svg" , static_files:: TOGGLE_MINUS_SVG ) ,
214
+ )
215
+ . replace (
216
+ "/* AUTOREPLACE: */url(\" toggle-plus.svg\" )" ,
217
+ & css_icon_url ( "toggle-plus.svg" , static_files:: TOGGLE_PLUS_SVG ) ,
206
218
)
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" ) ) ,
219
+ . replace (
220
+ "/* AUTOREPLACE: */url(\" down-arrow.svg\" )" ,
221
+ & css_icon_url ( "down-arrow.svg" , static_files:: DOWN_ARROW_SVG ) ,
222
+ ) ,
209
223
cx,
210
224
options,
211
225
) ?;
@@ -250,9 +264,14 @@ pub(super) fn write_shared(
250
264
write_toolchain ( "brush.svg" , static_files:: BRUSH_SVG ) ?;
251
265
write_toolchain ( "wheel.svg" , static_files:: WHEEL_SVG ) ?;
252
266
write_toolchain ( "clipboard.svg" , static_files:: CLIPBOARD_SVG ) ?;
253
- write_toolchain ( "down-arrow.svg" , static_files:: DOWN_ARROW_SVG ) ?;
254
- write_toolchain ( "toggle-minus.svg" , static_files:: TOGGLE_MINUS_PNG ) ?;
255
- write_toolchain ( "toggle-plus.svg" , static_files:: TOGGLE_PLUS_PNG ) ?;
267
+
268
+ // The following icons are embeded in the CSS file,
269
+ // unless we're in tweak-the-theme-mode.
270
+ if !options. enable_minification {
271
+ write_toolchain ( "down-arrow.svg" , static_files:: DOWN_ARROW_SVG ) ?;
272
+ write_toolchain ( "toggle-minus.svg" , static_files:: TOGGLE_MINUS_SVG ) ?;
273
+ write_toolchain ( "toggle-plus.svg" , static_files:: TOGGLE_PLUS_SVG ) ?;
274
+ }
256
275
257
276
let mut themes: Vec < & String > = themes. iter ( ) . collect ( ) ;
258
277
themes. sort ( ) ;
0 commit comments