@@ -52,7 +52,7 @@ use std::sync::Arc;
52
52
53
53
use externalfiles:: ExternalHtml ;
54
54
55
- use serialize:: json:: { self , ToJson } ;
55
+ use serialize:: json:: as_json ;
56
56
use syntax:: { abi, ast} ;
57
57
use syntax:: feature_gate:: UnstableFeatures ;
58
58
use rustc:: middle:: cstore:: LOCAL_CRATE ;
@@ -534,8 +534,8 @@ pub fn run(mut krate: clean::Crate,
534
534
cx. krate ( krate)
535
535
}
536
536
537
+ /// Build the search index from the collected metadata
537
538
fn build_index ( krate : & clean:: Crate , cache : & mut Cache ) -> String {
538
- // Build the search index from the collected metadata
539
539
let mut nodeid_to_pathid = HashMap :: new ( ) ;
540
540
let mut pathid_to_nodeid = Vec :: new ( ) ;
541
541
{
@@ -582,7 +582,13 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
582
582
583
583
// Collect the index into a string
584
584
let mut w = io:: Cursor :: new ( Vec :: new ( ) ) ;
585
- write ! ( & mut w, r#"searchIndex['{}'] = {{"items":["# , krate. name) . unwrap ( ) ;
585
+ let krate_doc = krate. module . as_ref ( ) . map ( |module| {
586
+ Escape ( & shorter ( module. doc_value ( ) ) ) . to_string ( )
587
+ } ) . unwrap_or ( "" . to_owned ( ) ) ;
588
+
589
+ write ! ( & mut w, r#"searchIndex[{}] = {{doc: {}, "items":["# ,
590
+ as_json( & krate. name) ,
591
+ as_json( & krate_doc) ) . unwrap ( ) ;
586
592
587
593
let mut lastpath = "" . to_string ( ) ;
588
594
for ( i, item) in cache. search_index . iter ( ) . enumerate ( ) {
@@ -598,9 +604,9 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
598
604
if i > 0 {
599
605
write ! ( & mut w, "," ) . unwrap ( ) ;
600
606
}
601
- write ! ( & mut w, r# "[{},"{}","{}" ,{}"# ,
602
- item. ty as usize , item . name , path ,
603
- item. desc . to_json ( ) . to_string ( ) ) . unwrap ( ) ;
607
+ write ! ( & mut w, "[{},{},{} ,{}" ,
608
+ item. ty as usize ,
609
+ as_json ( & item. name ) , as_json ( & path ) , as_json ( & item . desc ) ) . unwrap ( ) ;
604
610
match item. parent {
605
611
Some ( nodeid) => {
606
612
let pathid = * nodeid_to_pathid. get ( & nodeid) . unwrap ( ) ;
@@ -693,7 +699,7 @@ fn write_shared(cx: &Context,
693
699
if !line. starts_with ( key) {
694
700
continue
695
701
}
696
- if line. starts_with ( & format ! ( "{}['{}']" , key, krate) ) {
702
+ if line. starts_with ( & format ! ( r# "{}["{}"]"# , key, krate) ) {
697
703
continue
698
704
}
699
705
ret. push ( line. to_string ( ) ) ;
@@ -1387,7 +1393,7 @@ impl Context {
1387
1393
let js_dst = this. dst . join ( "sidebar-items.js" ) ;
1388
1394
let mut js_out = BufWriter :: new ( try_err ! ( File :: create( & js_dst) , & js_dst) ) ;
1389
1395
try_err ! ( write!( & mut js_out, "initSidebarItems({});" ,
1390
- json :: as_json( & items) ) , & js_dst) ;
1396
+ as_json( & items) ) , & js_dst) ;
1391
1397
}
1392
1398
1393
1399
for item in m. items {
0 commit comments