3232//! for creating the corresponding search index and source file renderings.
3333//! These threads are not parallelized (they haven't been a bottleneck yet), and
3434//! both occur before the crate is rendered.
35+
3536pub use self :: ExternalLocation :: * ;
3637
3738use std:: borrow:: Cow ;
@@ -128,6 +129,9 @@ pub struct SharedContext {
128129 pub sort_modules_alphabetically : bool ,
129130 /// Additional themes to be added to the generated docs.
130131 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 ,
131135}
132136
133137impl SharedContext {
@@ -492,6 +496,7 @@ pub fn run(mut krate: clean::Crate,
492496 external_html : & ExternalHtml ,
493497 playground_url : Option < String > ,
494498 dst : PathBuf ,
499+ resource_suffix : String ,
495500 passes : FxHashSet < String > ,
496501 css_file_extension : Option < PathBuf > ,
497502 renderinfo : RenderInfo ,
@@ -520,6 +525,7 @@ pub fn run(mut krate: clean::Crate,
520525 created_dirs : RefCell :: new ( FxHashSet ( ) ) ,
521526 sort_modules_alphabetically,
522527 themes,
528+ resource_suffix,
523529 } ;
524530
525531 // If user passed in `--playground-url` arg, we fill in crate name here
@@ -734,7 +740,7 @@ fn write_shared(cx: &Context,
734740 // Add all the static files. These may already exist, but we just
735741 // overwrite them anyway to make sure that they're fresh and up-to-date.
736742
737- write ( cx. dst . join ( "rustdoc.css" ) ,
743+ write ( cx. dst . join ( & format ! ( "rustdoc{} .css" , cx . shared . resource_suffix ) ) ,
738744 include_bytes ! ( "static/rustdoc.css" ) ) ?;
739745
740746 // 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,
746752
747753 let mut f = try_err ! ( File :: open( & entry) , & entry) ;
748754 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 ( ) ) ;
751760 }
752761
753- write ( cx. dst . join ( "brush.svg" ) ,
762+ write ( cx. dst . join ( & format ! ( "brush{} .svg" , cx . shared . resource_suffix ) ) ,
754763 include_bytes ! ( "static/brush.svg" ) ) ?;
755- write ( cx. dst . join ( "main.css" ) ,
764+ write ( cx. dst . join ( & format ! ( "main{} .css" , cx . shared . resource_suffix ) ) ,
756765 include_bytes ! ( "static/themes/main.css" ) ) ?;
757766 themes. insert ( "main" . to_owned ( ) ) ;
758- write ( cx. dst . join ( "dark.css" ) ,
767+ write ( cx. dst . join ( & format ! ( "dark{} .css" , cx . shared . resource_suffix ) ) ,
759768 include_bytes ! ( "static/themes/dark.css" ) ) ?;
760769 themes. insert ( "dark" . to_owned ( ) ) ;
761770
762771 let mut themes: Vec < & String > = themes. iter ( ) . collect ( ) ;
763772 themes. sort ( ) ;
764773 // To avoid theme switch latencies as much as possible, we put everything theme related
765774 // 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 ! (
767777r#"var themes = document.getElementById("theme-choices");
768778var themePicker = document.getElementById("theme-picker");
769779themePicker.onclick = function() {{
@@ -785,19 +795,28 @@ themePicker.onclick = function() {{
785795 }};
786796 themes.appendChild(but);
787797}});
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" ) ) ?;
792807
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+ }
795814
796815 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 ) ) ;
798817 try_err ! ( fs:: copy( css, out) , css) ;
799818 }
800- write ( cx. dst . join ( "normalize.css" ) ,
819+ write ( cx. dst . join ( & format ! ( "normalize{} .css" , cx . shared . resource_suffix ) ) ,
801820 include_bytes ! ( "static/normalize.css" ) ) ?;
802821 write ( cx. dst . join ( "FiraSans-Regular.woff" ) ,
803822 include_bytes ! ( "static/FiraSans-Regular.woff" ) ) ?;
@@ -1084,6 +1103,7 @@ impl<'a> SourceCollector<'a> {
10841103 root_path : & root_path,
10851104 description : & desc,
10861105 keywords : BASIC_KEYWORDS ,
1106+ resource_suffix : & self . scx . resource_suffix ,
10871107 } ;
10881108 layout:: render ( & mut w, & self . scx . layout ,
10891109 & page, & ( "" ) , & Source ( contents) ,
@@ -1446,6 +1466,7 @@ impl Context {
14461466 title : & title,
14471467 description : & desc,
14481468 keywords : & keywords,
1469+ resource_suffix : & self . shared . resource_suffix ,
14491470 } ;
14501471
14511472 reset_ids ( true ) ;
0 commit comments