@@ -132,6 +132,8 @@ pub struct SharedContext {
132132 /// This flag indicates whether listings of modules (in the side bar and documentation itself)
133133 /// should be ordered alphabetically or in order of appearance (in the source code).
134134 pub sort_modules_alphabetically : bool ,
135+ /// Additional themes to be added to the generated docs.
136+ pub themes : Vec < PathBuf > ,
135137}
136138
137139impl SharedContext {
@@ -500,7 +502,8 @@ pub fn run(mut krate: clean::Crate,
500502 renderinfo : RenderInfo ,
501503 render_type : RenderType ,
502504 sort_modules_alphabetically : bool ,
503- deny_render_differences : bool ) -> Result < ( ) , Error > {
505+ deny_render_differences : bool ,
506+ themes : Vec < PathBuf > ) -> Result < ( ) , Error > {
504507 let src_root = match krate. src {
505508 FileName :: Real ( ref p) => match p. parent ( ) {
506509 Some ( p) => p. to_path_buf ( ) ,
@@ -524,6 +527,7 @@ pub fn run(mut krate: clean::Crate,
524527 markdown_warnings : RefCell :: new ( vec ! [ ] ) ,
525528 created_dirs : RefCell :: new ( FxHashSet ( ) ) ,
526529 sort_modules_alphabetically,
530+ themes,
527531 } ;
528532
529533 // If user passed in `--playground-url` arg, we fill in crate name here
@@ -872,19 +876,28 @@ fn write_shared(cx: &Context,
872876
873877 write ( cx. dst . join ( "rustdoc.css" ) ,
874878 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 {
879885 let mut content = Vec :: with_capacity ( 100000 ) ;
880886
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 ( ) ) ;
887891 }
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 ( ) ;
888901 themes. sort ( ) ;
889902 // To avoid theme switch latencies as much as possible, we put everything theme related
890903 // at the beginning of the html files into another js file.
0 commit comments