@@ -859,9 +859,11 @@ themePicker.onblur = handleThemeButtonsBlur;
859
859
write_minify ( cx. dst . join ( & format ! ( "settings{}.js" , cx. shared. resource_suffix) ) ,
860
860
static_files:: SETTINGS_JS ,
861
861
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
+ }
865
867
866
868
{
867
869
let mut data = format ! ( "var resourcesSuffix = \" {}\" ;\n " ,
@@ -990,8 +992,8 @@ themePicker.onblur = handleThemeButtonsBlur;
990
992
}
991
993
}
992
994
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 ( ) ;
995
997
subs. sort_unstable_by ( |a, b| a. elem . cmp ( & b. elem ) ) ;
996
998
let mut files = self . elems . iter ( )
997
999
. map ( |s| format ! ( "\" {}\" " ,
@@ -1002,46 +1004,52 @@ themePicker.onblur = handleThemeButtonsBlur;
1002
1004
// FIXME(imperio): we could avoid to generate "dirs" and "files" if they're empty.
1003
1005
format ! ( "{{\" name\" :\" {name}\" ,\" dirs\" :[{subs}],\" files\" :[{files}]}}" ,
1004
1006
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( "," ) ,
1006
1008
files=files. join( "," ) )
1007
1009
}
1008
1010
}
1009
1011
1010
- use std:: path:: Component ;
1012
+ if cx. shared . include_sources {
1013
+ use std:: path:: Component ;
1011
1014
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
+ }
1034
1038
}
1035
1039
}
1036
- }
1037
1040
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
+ }
1045
1053
1046
1054
// Update the search index
1047
1055
let dst = cx. dst . join ( "search-index.js" ) ;
@@ -1367,7 +1375,7 @@ impl<'a> SourceCollector<'a> {
1367
1375
layout:: render ( & mut w, & self . scx . layout ,
1368
1376
& page, & ( "" ) , & Source ( contents) ,
1369
1377
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" ] ) ?;
1371
1379
w. flush ( ) ?;
1372
1380
self . scx . local_sources . insert ( p. clone ( ) , href) ;
1373
1381
Ok ( ( ) )
0 commit comments