@@ -132,6 +132,8 @@ pub struct SharedContext {
132
132
/// This flag indicates whether listings of modules (in the side bar and documentation itself)
133
133
/// should be ordered alphabetically or in order of appearance (in the source code).
134
134
pub sort_modules_alphabetically : bool ,
135
+ /// Additional themes to be added to the generated docs.
136
+ pub themes : Vec < PathBuf > ,
135
137
}
136
138
137
139
impl SharedContext {
@@ -500,7 +502,8 @@ pub fn run(mut krate: clean::Crate,
500
502
renderinfo : RenderInfo ,
501
503
render_type : RenderType ,
502
504
sort_modules_alphabetically : bool ,
503
- deny_render_differences : bool ) -> Result < ( ) , Error > {
505
+ deny_render_differences : bool ,
506
+ themes : Vec < PathBuf > ) -> Result < ( ) , Error > {
504
507
let src_root = match krate. src {
505
508
FileName :: Real ( ref p) => match p. parent ( ) {
506
509
Some ( p) => p. to_path_buf ( ) ,
@@ -524,6 +527,7 @@ pub fn run(mut krate: clean::Crate,
524
527
markdown_warnings : RefCell :: new ( vec ! [ ] ) ,
525
528
created_dirs : RefCell :: new ( FxHashSet ( ) ) ,
526
529
sort_modules_alphabetically,
530
+ themes,
527
531
} ;
528
532
529
533
// If user passed in `--playground-url` arg, we fill in crate name here
@@ -872,19 +876,28 @@ fn write_shared(cx: &Context,
872
876
873
877
write ( cx. dst . join ( "rustdoc.css" ) ,
874
878
include_bytes ! ( "static/rustdoc.css" ) ) ?;
875
- let path = cx. shared . src_root . join ( "../librustdoc/html/static/themes" ) ;
876
- let mut themes: Vec < String > = Vec :: new ( ) ;
877
- for entry in try_err ! ( fs:: read_dir( path. clone( ) ) , & path) {
878
- let entry = try_err ! ( entry, & path) ;
879
+
880
+ // To avoid "main.css" to be overwritten, we'll first run over the received themes and only
881
+ // then we'll run over the "official" styles.
882
+ let mut themes: HashSet < String > = HashSet :: new ( ) ;
883
+
884
+ for entry in & cx. shared . themes {
879
885
let mut content = Vec :: with_capacity ( 100000 ) ;
880
886
881
- let mut f = try_err ! ( File :: open( entry. path( ) ) , & entry. path( ) ) ;
882
- try_err ! ( f. read_to_end( & mut content) , & entry. path( ) ) ;
883
- write ( cx. dst . join ( entry. file_name ( ) ) , content. as_slice ( ) ) ?;
884
- themes. push ( try_none ! (
885
- try_none!( entry. path( ) . file_stem( ) , & entry. path( ) ) . to_str( ) ,
886
- & entry. path( ) ) . to_owned ( ) ) ;
887
+ let mut f = try_err ! ( File :: open( & entry) , & entry) ;
888
+ try_err ! ( f. read_to_end( & mut content) , & entry) ;
889
+ write ( cx. dst . join ( try_none ! ( entry. file_name( ) , & entry) ) , content. as_slice ( ) ) ?;
890
+ themes. insert ( try_none ! ( try_none!( entry. file_stem( ) , & entry) . to_str( ) , & entry) . to_owned ( ) ) ;
887
891
}
892
+
893
+ write ( cx. dst . join ( "main.css" ) ,
894
+ include_bytes ! ( "static/themes/main.css" ) ) ?;
895
+ themes. insert ( "main" . to_owned ( ) ) ;
896
+ write ( cx. dst . join ( "dark.css" ) ,
897
+ include_bytes ! ( "static/themes/dark.css" ) ) ?;
898
+ themes. insert ( "dark" . to_owned ( ) ) ;
899
+
900
+ let mut themes: Vec < & String > = themes. iter ( ) . collect ( ) ;
888
901
themes. sort ( ) ;
889
902
// To avoid theme switch latencies as much as possible, we put everything theme related
890
903
// at the beginning of the html files into another js file.
0 commit comments