32
32
//! for creating the corresponding search index and source file renderings.
33
33
//! These threads are not parallelized (they haven't been a bottleneck yet), and
34
34
//! both occur before the crate is rendered.
35
+
35
36
pub use self :: ExternalLocation :: * ;
36
37
37
38
use std:: borrow:: Cow ;
@@ -128,6 +129,9 @@ pub struct SharedContext {
128
129
pub sort_modules_alphabetically : bool ,
129
130
/// Additional themes to be added to the generated docs.
130
131
pub themes : Vec < PathBuf > ,
132
+ /// Suffix to be added on resource files (if suffix is "-v2" then "main.css" becomes
133
+ /// "main-v2.css").
134
+ pub resource_suffix : String ,
131
135
}
132
136
133
137
impl SharedContext {
@@ -492,6 +496,7 @@ pub fn run(mut krate: clean::Crate,
492
496
external_html : & ExternalHtml ,
493
497
playground_url : Option < String > ,
494
498
dst : PathBuf ,
499
+ resource_suffix : String ,
495
500
passes : FxHashSet < String > ,
496
501
css_file_extension : Option < PathBuf > ,
497
502
renderinfo : RenderInfo ,
@@ -520,6 +525,7 @@ pub fn run(mut krate: clean::Crate,
520
525
created_dirs : RefCell :: new ( FxHashSet ( ) ) ,
521
526
sort_modules_alphabetically,
522
527
themes,
528
+ resource_suffix,
523
529
} ;
524
530
525
531
// If user passed in `--playground-url` arg, we fill in crate name here
@@ -734,7 +740,7 @@ fn write_shared(cx: &Context,
734
740
// Add all the static files. These may already exist, but we just
735
741
// overwrite them anyway to make sure that they're fresh and up-to-date.
736
742
737
- write ( cx. dst . join ( "rustdoc.css" ) ,
743
+ write ( cx. dst . join ( & format ! ( "rustdoc{} .css" , cx . shared . resource_suffix ) ) ,
738
744
include_bytes ! ( "static/rustdoc.css" ) ) ?;
739
745
740
746
// To avoid "main.css" to be overwritten, we'll first run over the received themes and only
@@ -746,24 +752,28 @@ fn write_shared(cx: &Context,
746
752
747
753
let mut f = try_err ! ( File :: open( & entry) , & entry) ;
748
754
try_err ! ( f. read_to_end( & mut content) , & entry) ;
749
- write ( cx. dst . join ( try_none ! ( entry. file_name( ) , & entry) ) , content. as_slice ( ) ) ?;
750
- themes. insert ( try_none ! ( try_none!( entry. file_stem( ) , & entry) . to_str( ) , & entry) . to_owned ( ) ) ;
755
+ let theme = try_none ! ( try_none!( entry. file_stem( ) , & entry) . to_str( ) , & entry) ;
756
+ let extension = try_none ! ( try_none!( entry. extension( ) , & entry) . to_str( ) , & entry) ;
757
+ write ( cx. dst . join ( format ! ( "{}{}.{}" , theme, cx. shared. resource_suffix, extension) ) ,
758
+ content. as_slice ( ) ) ?;
759
+ themes. insert ( theme. to_owned ( ) ) ;
751
760
}
752
761
753
- write ( cx. dst . join ( "brush.svg" ) ,
762
+ write ( cx. dst . join ( & format ! ( "brush{} .svg" , cx . shared . resource_suffix ) ) ,
754
763
include_bytes ! ( "static/brush.svg" ) ) ?;
755
- write ( cx. dst . join ( "main.css" ) ,
764
+ write ( cx. dst . join ( & format ! ( "main{} .css" , cx . shared . resource_suffix ) ) ,
756
765
include_bytes ! ( "static/themes/main.css" ) ) ?;
757
766
themes. insert ( "main" . to_owned ( ) ) ;
758
- write ( cx. dst . join ( "dark.css" ) ,
767
+ write ( cx. dst . join ( & format ! ( "dark{} .css" , cx . shared . resource_suffix ) ) ,
759
768
include_bytes ! ( "static/themes/dark.css" ) ) ?;
760
769
themes. insert ( "dark" . to_owned ( ) ) ;
761
770
762
771
let mut themes: Vec < & String > = themes. iter ( ) . collect ( ) ;
763
772
themes. sort ( ) ;
764
773
// To avoid theme switch latencies as much as possible, we put everything theme related
765
774
// at the beginning of the html files into another js file.
766
- write ( cx. dst . join ( "theme.js" ) , format ! (
775
+ write ( cx. dst . join ( & format ! ( "theme{}.js" , cx. shared. resource_suffix) ) ,
776
+ format ! (
767
777
r#"var themes = document.getElementById("theme-choices");
768
778
var themePicker = document.getElementById("theme-picker");
769
779
themePicker.onclick = function() {{
@@ -785,19 +795,28 @@ themePicker.onclick = function() {{
785
795
}};
786
796
themes.appendChild(but);
787
797
}});
788
- "# , themes. iter( )
789
- . map( |s| format!( "\" {}\" " , s) )
790
- . collect:: <Vec <String >>( )
791
- . join( "," ) ) . as_bytes ( ) ) ?;
798
+ "# ,
799
+ themes. iter( )
800
+ . map( |s| format!( "\" {}\" " , s) )
801
+ . collect:: <Vec <String >>( )
802
+ . join( "," ) ) . as_bytes ( ) ,
803
+ ) ?;
804
+
805
+ write ( cx. dst . join ( & format ! ( "main{}.js" , cx. shared. resource_suffix) ) ,
806
+ include_bytes ! ( "static/main.js" ) ) ?;
792
807
793
- write ( cx. dst . join ( "main.js" ) , include_bytes ! ( "static/main.js" ) ) ?;
794
- write ( cx. dst . join ( "storage.js" ) , include_bytes ! ( "static/storage.js" ) ) ?;
808
+ {
809
+ let mut data = format ! ( "var resourcesSuffix = \" {}\" ;\n " ,
810
+ cx. shared. resource_suffix) . into_bytes ( ) ;
811
+ data. extend_from_slice ( include_bytes ! ( "static/storage.js" ) ) ;
812
+ write ( cx. dst . join ( & format ! ( "storage{}.js" , cx. shared. resource_suffix) ) , & data) ?;
813
+ }
795
814
796
815
if let Some ( ref css) = cx. shared . css_file_extension {
797
- let out = cx. dst . join ( "theme.css" ) ;
816
+ let out = cx. dst . join ( & format ! ( "theme{} .css" , cx . shared . resource_suffix ) ) ;
798
817
try_err ! ( fs:: copy( css, out) , css) ;
799
818
}
800
- write ( cx. dst . join ( "normalize.css" ) ,
819
+ write ( cx. dst . join ( & format ! ( "normalize{} .css" , cx . shared . resource_suffix ) ) ,
801
820
include_bytes ! ( "static/normalize.css" ) ) ?;
802
821
write ( cx. dst . join ( "FiraSans-Regular.woff" ) ,
803
822
include_bytes ! ( "static/FiraSans-Regular.woff" ) ) ?;
@@ -1084,6 +1103,7 @@ impl<'a> SourceCollector<'a> {
1084
1103
root_path : & root_path,
1085
1104
description : & desc,
1086
1105
keywords : BASIC_KEYWORDS ,
1106
+ resource_suffix : & self . scx . resource_suffix ,
1087
1107
} ;
1088
1108
layout:: render ( & mut w, & self . scx . layout ,
1089
1109
& page, & ( "" ) , & Source ( contents) ,
@@ -1446,6 +1466,7 @@ impl Context {
1446
1466
title : & title,
1447
1467
description : & desc,
1448
1468
keywords : & keywords,
1469
+ resource_suffix : & self . shared . resource_suffix ,
1449
1470
} ;
1450
1471
1451
1472
reset_ids ( true ) ;
0 commit comments