@@ -212,6 +212,26 @@ crate struct SharedContext {
212
212
playground : Option < markdown:: Playground > ,
213
213
}
214
214
215
+ impl Context {
216
+ fn path ( & self , filename : & str ) -> PathBuf {
217
+ // We use splitn vs Path::extension here because we might get a filename
218
+ // like `style.min.css` and we want to process that into
219
+ // `style-suffix.min.css`. Path::extension would just return `css`
220
+ // which would result in `style.min-suffix.css` which isn't what we
221
+ // want.
222
+ let mut iter = filename. splitn ( 2 , '.' ) ;
223
+ let base = iter. next ( ) . unwrap ( ) ;
224
+ let ext = iter. next ( ) . unwrap ( ) ;
225
+ let filename = format ! (
226
+ "{}{}.{}" ,
227
+ base,
228
+ self . shared. resource_suffix,
229
+ ext,
230
+ ) ;
231
+ self . dst . join ( & filename)
232
+ }
233
+ }
234
+
215
235
impl SharedContext {
216
236
crate fn ensure_dir ( & self , dst : & Path ) -> Result < ( ) , Error > {
217
237
let mut dirs = self . created_dirs . borrow_mut ( ) ;
@@ -530,13 +550,13 @@ fn write_shared(
530
550
// Add all the static files. These may already exist, but we just
531
551
// overwrite them anyway to make sure that they're fresh and up-to-date.
532
552
533
- write_minify ( & cx. shared . fs , cx. dst . join ( & format ! ( "rustdoc{} .css" , cx . shared . resource_suffix ) ) ,
553
+ write_minify ( & cx. shared . fs , cx. path ( "rustdoc.css" ) ,
534
554
static_files:: RUSTDOC_CSS ,
535
555
options. enable_minification ) ?;
536
- write_minify ( & cx. shared . fs , cx. dst . join ( & format ! ( "settings{} .css" , cx . shared . resource_suffix ) ) ,
556
+ write_minify ( & cx. shared . fs , cx. path ( "settings.css" ) ,
537
557
static_files:: SETTINGS_CSS ,
538
558
options. enable_minification ) ?;
539
- write_minify ( & cx. shared . fs , cx. dst . join ( & format ! ( "noscript{} .css" , cx . shared . resource_suffix ) ) ,
559
+ write_minify ( & cx. shared . fs , cx. path ( "noscript.css" ) ,
540
560
static_files:: NOSCRIPT_CSS ,
541
561
options. enable_minification ) ?;
542
562
@@ -548,34 +568,25 @@ fn write_shared(
548
568
let content = try_err ! ( fs:: read( & entry) , & entry) ;
549
569
let theme = try_none ! ( try_none!( entry. file_stem( ) , & entry) . to_str( ) , & entry) ;
550
570
let extension = try_none ! ( try_none!( entry. extension( ) , & entry) . to_str( ) , & entry) ;
551
- cx. shared . fs . write (
552
- cx. dst . join ( format ! ( "{}{}.{}" , theme, cx. shared. resource_suffix, extension) ) ,
553
- content. as_slice ( ) ) ?;
571
+ cx. shared . fs . write ( cx. path ( & format ! ( "{}.{}" , theme, extension) ) , content. as_slice ( ) ) ?;
554
572
themes. insert ( theme. to_owned ( ) ) ;
555
573
}
556
574
557
575
let write = |p, c| { cx. shared . fs . write ( p, c) } ;
558
576
if ( * cx. shared ) . layout . logo . is_empty ( ) {
559
- write ( cx. dst . join ( & format ! ( "rust-logo{}.png" , cx. shared. resource_suffix) ) ,
560
- static_files:: RUST_LOGO ) ?;
577
+ write ( cx. path ( "rust-log.png" ) , static_files:: RUST_LOGO ) ?;
561
578
}
562
579
if ( * cx. shared ) . layout . favicon . is_empty ( ) {
563
- write ( cx. dst . join ( & format ! ( "favicon{}.ico" , cx. shared. resource_suffix) ) ,
564
- static_files:: RUST_FAVICON ) ?;
565
- }
566
- write ( cx. dst . join ( & format ! ( "brush{}.svg" , cx. shared. resource_suffix) ) ,
567
- static_files:: BRUSH_SVG ) ?;
568
- write ( cx. dst . join ( & format ! ( "wheel{}.svg" , cx. shared. resource_suffix) ) ,
569
- static_files:: WHEEL_SVG ) ?;
570
- write ( cx. dst . join ( & format ! ( "down-arrow{}.svg" , cx. shared. resource_suffix) ) ,
571
- static_files:: DOWN_ARROW_SVG ) ?;
572
- write_minify ( & cx. shared . fs , cx. dst . join ( & format ! ( "light{}.css" , cx. shared. resource_suffix) ) ,
573
- static_files:: themes:: LIGHT ,
574
- options. enable_minification ) ?;
580
+ write ( cx. path ( "favicon.ico" ) , static_files:: RUST_FAVICON ) ?;
581
+ }
582
+ write ( cx. path ( "brush.svg" ) , static_files:: BRUSH_SVG ) ?;
583
+ write ( cx. path ( "wheel.svg" ) , static_files:: WHEEL_SVG ) ?;
584
+ write ( cx. path ( "down-arrow.svg" ) , static_files:: DOWN_ARROW_SVG ) ?;
585
+ write_minify ( & cx. shared . fs ,
586
+ cx. path ( "light.css" ) , static_files:: themes:: LIGHT , options. enable_minification ) ?;
575
587
themes. insert ( "light" . to_owned ( ) ) ;
576
- write_minify ( & cx. shared . fs , cx. dst . join ( & format ! ( "dark{}.css" , cx. shared. resource_suffix) ) ,
577
- static_files:: themes:: DARK ,
578
- options. enable_minification ) ?;
588
+ write_minify ( & cx. shared . fs ,
589
+ cx. path ( "dark.css" ) , static_files:: themes:: DARK , options. enable_minification ) ?;
579
590
themes. insert ( "dark" . to_owned ( ) ) ;
580
591
581
592
let mut themes: Vec < & String > = themes. iter ( ) . collect ( ) ;
@@ -638,40 +649,40 @@ themePicker.onblur = handleThemeButtonsBlur;
638
649
theme_js. as_bytes ( )
639
650
) ?;
640
651
641
- write_minify ( & cx. shared . fs , cx. dst . join ( & format ! ( "main{} .js" , cx . shared . resource_suffix ) ) ,
652
+ write_minify ( & cx. shared . fs , cx. path ( "main.js" ) ,
642
653
static_files:: MAIN_JS ,
643
654
options. enable_minification ) ?;
644
- write_minify ( & cx. shared . fs , cx. dst . join ( & format ! ( "settings{} .js" , cx . shared . resource_suffix ) ) ,
655
+ write_minify ( & cx. shared . fs , cx. path ( "settings.js" ) ,
645
656
static_files:: SETTINGS_JS ,
646
657
options. enable_minification ) ?;
647
658
if cx. shared . include_sources {
648
659
write_minify (
649
660
& cx. shared . fs ,
650
- cx. dst . join ( & format ! ( "source-script{} .js" , cx . shared . resource_suffix ) ) ,
661
+ cx. path ( "source-script.js" ) ,
651
662
static_files:: sidebar:: SOURCE_SCRIPT ,
652
663
options. enable_minification ) ?;
653
664
}
654
665
655
666
{
656
667
write_minify (
657
668
& cx. shared . fs ,
658
- cx. dst . join ( & format ! ( "storage{} .js" , cx . shared . resource_suffix ) ) ,
669
+ cx. path ( "storage.js" ) ,
659
670
& format ! ( "var resourcesSuffix = \" {}\" ;{}" ,
660
671
cx. shared. resource_suffix,
661
672
static_files:: STORAGE_JS ) ,
662
673
options. enable_minification ) ?;
663
674
}
664
675
665
676
if let Some ( ref css) = cx. shared . layout . css_file_extension {
666
- let out = cx. dst . join ( & format ! ( "theme{} .css" , cx . shared . resource_suffix ) ) ;
677
+ let out = cx. path ( "theme.css" ) ;
667
678
let buffer = try_err ! ( fs:: read_to_string( css) , css) ;
668
679
if !options. enable_minification {
669
680
cx. shared . fs . write ( & out, & buffer) ?;
670
681
} else {
671
682
write_minify ( & cx. shared . fs , out, & buffer, options. enable_minification ) ?;
672
683
}
673
684
}
674
- write_minify ( & cx. shared . fs , cx. dst . join ( & format ! ( "normalize{} .css" , cx . shared . resource_suffix ) ) ,
685
+ write_minify ( & cx. shared . fs , cx. path ( "normalize.css" ) ,
675
686
static_files:: NORMALIZE_CSS ,
676
687
options. enable_minification ) ?;
677
688
write ( cx. dst . join ( "FiraSans-Regular.woff" ) ,
0 commit comments