@@ -859,9 +859,11 @@ themePicker.onblur = handleThemeButtonsBlur;
859859 write_minify ( cx. dst . join ( & format ! ( "settings{}.js" , cx. shared. resource_suffix) ) ,
860860 static_files:: SETTINGS_JS ,
861861 options. enable_minification ) ?;
862- write_minify ( cx. dst . join ( & format ! ( "source-script{}.js" , cx. shared. resource_suffix) ) ,
863- include_str ! ( "static/source-script.js" ) ,
864- options. enable_minification ) ?;
862+ if cx. shared . include_sources {
863+ write_minify ( cx. dst . join ( & format ! ( "source-script{}.js" , cx. shared. resource_suffix) ) ,
864+ static_files:: sidebar:: SOURCE_SCRIPT ,
865+ options. enable_minification ) ?;
866+ }
865867
866868 {
867869 let mut data = format ! ( "var resourcesSuffix = \" {}\" ;\n " ,
@@ -990,8 +992,8 @@ themePicker.onblur = handleThemeButtonsBlur;
990992 }
991993 }
992994
993- fn to_string ( & self ) -> String {
994- let mut subs: Vec < & Hierarchy > = self . children . iter ( ) . map ( | ( _ , v ) | v ) . collect ( ) ;
995+ fn to_json_string ( & self ) -> String {
996+ let mut subs: Vec < & Hierarchy > = self . children . values ( ) . collect ( ) ;
995997 subs. sort_unstable_by ( |a, b| a. elem . cmp ( & b. elem ) ) ;
996998 let mut files = self . elems . iter ( )
997999 . map ( |s| format ! ( "\" {}\" " ,
@@ -1002,46 +1004,52 @@ themePicker.onblur = handleThemeButtonsBlur;
10021004 // FIXME(imperio): we could avoid to generate "dirs" and "files" if they're empty.
10031005 format ! ( "{{\" name\" :\" {name}\" ,\" dirs\" :[{subs}],\" files\" :[{files}]}}" ,
10041006 name=self . elem. to_str( ) . expect( "invalid osstring conversion" ) ,
1005- subs=subs. iter( ) . map( |s| s. to_string ( ) ) . collect:: <Vec <_>>( ) . join( "," ) ,
1007+ subs=subs. iter( ) . map( |s| s. to_json_string ( ) ) . collect:: <Vec <_>>( ) . join( "," ) ,
10061008 files=files. join( "," ) )
10071009 }
10081010 }
10091011
1010- use std:: path:: Component ;
1012+ if cx. shared . include_sources {
1013+ use std:: path:: Component ;
10111014
1012- let mut hierarchy = Hierarchy :: new ( OsString :: new ( ) ) ;
1013- for source in cx. shared . local_sources . iter ( )
1014- . filter_map ( |p| p. 0 . strip_prefix ( & cx. shared . src_root )
1015- . ok ( ) ) {
1016- let mut h = & mut hierarchy;
1017- let mut elems = source. components ( )
1018- . filter_map ( |s| {
1019- match s {
1020- Component :: Normal ( s) => Some ( s. to_owned ( ) ) ,
1021- _ => None ,
1022- }
1023- } )
1024- . peekable ( ) ;
1025- loop {
1026- let cur_elem = elems. next ( ) . expect ( "empty file path" ) ;
1027- if elems. peek ( ) . is_none ( ) {
1028- h. elems . insert ( cur_elem) ;
1029- break ;
1030- } else {
1031- let e = cur_elem. clone ( ) ;
1032- h. children . entry ( cur_elem. clone ( ) ) . or_insert_with ( || Hierarchy :: new ( e) ) ;
1033- h = h. children . get_mut ( & cur_elem) . expect ( "not found child" ) ;
1015+ let mut hierarchy = Hierarchy :: new ( OsString :: new ( ) ) ;
1016+ for source in cx. shared . local_sources . iter ( )
1017+ . filter_map ( |p| p. 0 . strip_prefix ( & cx. shared . src_root )
1018+ . ok ( ) ) {
1019+ let mut h = & mut hierarchy;
1020+ let mut elems = source. components ( )
1021+ . filter_map ( |s| {
1022+ match s {
1023+ Component :: Normal ( s) => Some ( s. to_owned ( ) ) ,
1024+ _ => None ,
1025+ }
1026+ } )
1027+ . peekable ( ) ;
1028+ loop {
1029+ let cur_elem = elems. next ( ) . expect ( "empty file path" ) ;
1030+ if elems. peek ( ) . is_none ( ) {
1031+ h. elems . insert ( cur_elem) ;
1032+ break ;
1033+ } else {
1034+ let e = cur_elem. clone ( ) ;
1035+ h. children . entry ( cur_elem. clone ( ) ) . or_insert_with ( || Hierarchy :: new ( e) ) ;
1036+ h = h. children . get_mut ( & cur_elem) . expect ( "not found child" ) ;
1037+ }
10341038 }
10351039 }
1036- }
10371040
1038- let dst = cx. dst . join ( "source-files.js" ) ;
1039- let ( mut all_sources, _krates) = try_err ! ( collect( & dst, & krate. name, "sourcesIndex" ) , & dst) ;
1040- all_sources. push ( format ! ( "sourcesIndex['{}'] = {};" , & krate. name, hierarchy. to_string( ) ) ) ;
1041- all_sources. sort ( ) ;
1042- let mut w = try_err ! ( File :: create( & dst) , & dst) ;
1043- try_err ! ( writeln!( & mut w, "var N = null;var sourcesIndex = {{}};\n {}" , all_sources. join( "\n " ) ) ,
1044- & dst) ;
1041+ let dst = cx. dst . join ( "source-files.js" ) ;
1042+ let ( mut all_sources, _krates) = try_err ! ( collect( & dst, & krate. name, "sourcesIndex" ) , & dst) ;
1043+ all_sources. push ( format ! ( "sourcesIndex['{}'] = {};" ,
1044+ & krate. name,
1045+ hierarchy. to_json_string( ) ) ) ;
1046+ all_sources. sort ( ) ;
1047+ let mut w = try_err ! ( File :: create( & dst) , & dst) ;
1048+ try_err ! ( writeln!( & mut w,
1049+ "var N = null;var sourcesIndex = {{}};\n {}" ,
1050+ all_sources. join( "\n " ) ) ,
1051+ & dst) ;
1052+ }
10451053
10461054 // Update the search index
10471055 let dst = cx. dst . join ( "search-index.js" ) ;
@@ -1367,7 +1375,7 @@ impl<'a> SourceCollector<'a> {
13671375 layout:: render ( & mut w, & self . scx . layout ,
13681376 & page, & ( "" ) , & Source ( contents) ,
13691377 self . scx . css_file_extension . is_some ( ) ,
1370- & self . scx . themes , & [ "source-files.js " , "source-script.js " ] ) ?;
1378+ & self . scx . themes , & [ "source-files" , "source-script" ] ) ?;
13711379 w. flush ( ) ?;
13721380 self . scx . local_sources . insert ( p. clone ( ) , href) ;
13731381 Ok ( ( ) )
0 commit comments