@@ -80,6 +80,8 @@ use html::{highlight, layout};
80
80
81
81
use minifier;
82
82
83
+ use pulldown_cmark;
84
+
83
85
/// A pair of name and its optional document.
84
86
pub type NameDoc = ( String , Option < String > ) ;
85
87
@@ -106,6 +108,8 @@ struct Context {
106
108
/// The map used to ensure all generated 'id=' attributes are unique.
107
109
id_map : Rc < RefCell < IdMap > > ,
108
110
pub shared : Arc < SharedContext > ,
111
+ pub enable_index_page : bool ,
112
+ pub index_page : Option < PathBuf > ,
109
113
}
110
114
111
115
struct SharedContext {
@@ -501,7 +505,10 @@ pub fn run(mut krate: clean::Crate,
501
505
sort_modules_alphabetically : bool ,
502
506
themes : Vec < PathBuf > ,
503
507
enable_minification : bool ,
504
- id_map : IdMap ) -> Result < ( ) , Error > {
508
+ id_map : IdMap ,
509
+ enable_index_page : bool ,
510
+ index_page : Option < PathBuf > ,
511
+ ) -> Result < ( ) , Error > {
505
512
let src_root = match krate. src {
506
513
FileName :: Real ( ref p) => match p. parent ( ) {
507
514
Some ( p) => p. to_path_buf ( ) ,
@@ -572,6 +579,8 @@ pub fn run(mut krate: clean::Crate,
572
579
codes : ErrorCodes :: from ( UnstableFeatures :: from_environment ( ) . is_nightly_build ( ) ) ,
573
580
id_map : Rc :: new ( RefCell :: new ( id_map) ) ,
574
581
shared : Arc :: new ( scx) ,
582
+ enable_index_page,
583
+ index_page,
575
584
} ;
576
585
577
586
// Crawl the crate to build various caches used for the output
@@ -902,8 +911,9 @@ themePicker.onblur = handleThemeButtonsBlur;
902
911
write ( cx. dst . join ( "COPYRIGHT.txt" ) ,
903
912
include_bytes ! ( "static/COPYRIGHT.txt" ) ) ?;
904
913
905
- fn collect ( path : & Path , krate : & str , key : & str ) -> io:: Result < Vec < String > > {
914
+ fn collect ( path : & Path , krate : & str , key : & str ) -> io:: Result < ( Vec < String > , Vec < String > ) > {
906
915
let mut ret = Vec :: new ( ) ;
916
+ let mut krates = Vec :: new ( ) ;
907
917
if path. exists ( ) {
908
918
for line in BufReader :: new ( File :: open ( path) ?) . lines ( ) {
909
919
let line = line?;
@@ -914,9 +924,13 @@ themePicker.onblur = handleThemeButtonsBlur;
914
924
continue ;
915
925
}
916
926
ret. push ( line. to_string ( ) ) ;
927
+ krates. push ( line[ key. len ( ) + 2 ..] . split ( '"' )
928
+ . next ( )
929
+ . map ( |s| s. to_owned ( ) )
930
+ . unwrap_or_else ( || String :: new ( ) ) ) ;
917
931
}
918
932
}
919
- Ok ( ret)
933
+ Ok ( ( ret, krates ) )
920
934
}
921
935
922
936
fn show_item ( item : & IndexItem , krate : & str ) -> String {
@@ -931,7 +945,7 @@ themePicker.onblur = handleThemeButtonsBlur;
931
945
932
946
let dst = cx. dst . join ( "aliases.js" ) ;
933
947
{
934
- let mut all_aliases = try_err ! ( collect( & dst, & krate. name, "ALIASES" ) , & dst) ;
948
+ let ( mut all_aliases, _ ) = try_err ! ( collect( & dst, & krate. name, "ALIASES" ) , & dst) ;
935
949
let mut w = try_err ! ( File :: create( & dst) , & dst) ;
936
950
let mut output = String :: with_capacity ( 100 ) ;
937
951
for ( alias, items) in & cache. aliases {
@@ -955,7 +969,7 @@ themePicker.onblur = handleThemeButtonsBlur;
955
969
956
970
// Update the search index
957
971
let dst = cx. dst . join ( "search-index.js" ) ;
958
- let mut all_indexes = try_err ! ( collect( & dst, & krate. name, "searchIndex" ) , & dst) ;
972
+ let ( mut all_indexes, mut krates ) = try_err ! ( collect( & dst, & krate. name, "searchIndex" ) , & dst) ;
959
973
all_indexes. push ( search_index) ;
960
974
// Sort the indexes by crate so the file will be generated identically even
961
975
// with rustdoc running in parallel.
@@ -969,6 +983,61 @@ themePicker.onblur = handleThemeButtonsBlur;
969
983
}
970
984
try_err ! ( writeln!( & mut w, "initSearch(searchIndex);" ) , & dst) ;
971
985
986
+ <<<<<<< HEAD
987
+ if cx. disable_index_page == false {
988
+ let dst = cx. dst. join( "index.html" ) ;
989
+ =======
990
+ if cx. enable_index_page == true {
991
+ >>>>>>> a2642cf... f
992
+ if let Some ( ref index_page) = cx. index_page {
993
+ let mut content = Vec :: with_capacity( 100000 ) ;
994
+
995
+ let mut f = try_err ! ( File :: open( & index_page) , & index_page) ;
996
+ try_err ! ( f. read_to_end( & mut content) , & index_page) ;
997
+ let content = match String :: from_utf8( content) {
998
+ Ok ( c) => c,
999
+ Err ( _) => return Err ( Error :: new(
1000
+ io:: Error :: new(
1001
+ io:: ErrorKind :: Other , "invalid markdown" ) ,
1002
+ & index_page) ) ,
1003
+ } ;
1004
+ let parser = pulldown_cmark:: Parser :: new ( & content ) ;
1005
+ let mut html_buf = String :: new( ) ;
1006
+ pulldown_cmark:: html:: push_html( & mut html_buf, parser) ;
1007
+ let mut f = try_err ! ( File :: create( & dst) , & dst) ;
1008
+ try_err ! ( f. write_all( html_buf. as_bytes( ) ) , & dst) ;
1009
+ } else {
1010
+ let mut w = BufWriter :: new( try_err ! ( File :: create( & dst) , & dst) ) ;
1011
+ let page = layout:: Page {
1012
+ title : "Index of crates" ,
1013
+ css_class : "mod" ,
1014
+ root_path : "./" ,
1015
+ description : "List of crates" ,
1016
+ keywords : BASIC_KEYWORDS ,
1017
+ resource_suffix : & cx. shared. resource_suffix,
1018
+ } ;
1019
+ krates. push( krate. name. clone( ) ) ;
1020
+ krates. sort( ) ;
1021
+ krates. dedup( ) ;
1022
+
1023
+ let content = format ! (
1024
+ "<h1 class='fqn'>\
1025
+ <span class='in-band'>List of all crates</span>\
1026
+ </h1><ul class='mod'>{}</ul>",
1027
+ krates
1028
+ . iter( )
1029
+ . map( |s| {
1030
+ format!( "<li><a href=\" {}/index.html\" >{}</li>" , s, s)
1031
+ } )
1032
+ . collect:: <String >( ) ) ;
1033
+ try_err ! ( layout:: render( & mut w, & cx. shared. layout,
1034
+ & page, & ( "" ) , & content,
1035
+ cx. shared. css_file_extension. is_some( ) ,
1036
+ & cx. shared. themes) , & dst) ;
1037
+ try_err ! ( w. flush( ) , & dst) ;
1038
+ }
1039
+ }
1040
+
972
1041
// Update the list of all implementors for traits
973
1042
let dst = cx. dst. join( "implementors" ) ;
974
1043
for ( & did, imps) in & cache. implementors {
@@ -1022,7 +1091,8 @@ themePicker.onblur = handleThemeButtonsBlur;
1022
1091
remote_item_type. css_class( ) ,
1023
1092
remote_path[ remote_path. len( ) - 1 ] ) ) ;
1024
1093
1025
- let mut all_implementors = try_err ! ( collect( & mydst, & krate. name, "implementors" ) , & mydst) ;
1094
+ let ( mut all_implementors, _) = try_err!( collect( & mydst, & krate. name, "implementors" ) ,
1095
+ & mydst) ;
1026
1096
all_implementors. push( implementors) ;
1027
1097
// Sort the implementors by crate so the file will be generated
1028
1098
// identically even with rustdoc running in parallel.
0 commit comments