@@ -52,7 +52,7 @@ use std::sync::Arc;
5252
5353use externalfiles:: ExternalHtml ;
5454
55- use serialize:: json:: { self , ToJson } ;
55+ use serialize:: json:: as_json ;
5656use syntax:: { abi, ast} ;
5757use syntax:: feature_gate:: UnstableFeatures ;
5858use rustc:: middle:: cstore:: LOCAL_CRATE ;
@@ -534,8 +534,8 @@ pub fn run(mut krate: clean::Crate,
534534 cx. krate ( krate)
535535}
536536
537+ /// Build the search index from the collected metadata
537538fn build_index ( krate : & clean:: Crate , cache : & mut Cache ) -> String {
538- // Build the search index from the collected metadata
539539 let mut nodeid_to_pathid = HashMap :: new ( ) ;
540540 let mut pathid_to_nodeid = Vec :: new ( ) ;
541541 {
@@ -582,7 +582,13 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
582582
583583 // Collect the index into a string
584584 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 ( ) ;
586592
587593 let mut lastpath = "" . to_string ( ) ;
588594 for ( i, item) in cache. search_index . iter ( ) . enumerate ( ) {
@@ -598,9 +604,9 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
598604 if i > 0 {
599605 write ! ( & mut w, "," ) . unwrap ( ) ;
600606 }
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 ( ) ;
604610 match item. parent {
605611 Some ( nodeid) => {
606612 let pathid = * nodeid_to_pathid. get ( & nodeid) . unwrap ( ) ;
@@ -693,7 +699,7 @@ fn write_shared(cx: &Context,
693699 if !line. starts_with ( key) {
694700 continue
695701 }
696- if line. starts_with ( & format ! ( "{}['{}']" , key, krate) ) {
702+ if line. starts_with ( & format ! ( r# "{}["{}"]"# , key, krate) ) {
697703 continue
698704 }
699705 ret. push ( line. to_string ( ) ) ;
@@ -1387,7 +1393,7 @@ impl Context {
13871393 let js_dst = this. dst . join ( "sidebar-items.js" ) ;
13881394 let mut js_out = BufWriter :: new ( try_err ! ( File :: create( & js_dst) , & js_dst) ) ;
13891395 try_err ! ( write!( & mut js_out, "initSidebarItems({});" ,
1390- json :: as_json( & items) ) , & js_dst) ;
1396+ as_json( & items) ) , & js_dst) ;
13911397 }
13921398
13931399 for item in m. items {
0 commit comments