Add crates to search-index
This commit is contained in:
parent
9a7913786c
commit
810a514029
3 changed files with 28 additions and 9 deletions
|
@ -52,7 +52,7 @@ use std::sync::Arc;
|
||||||
|
|
||||||
use externalfiles::ExternalHtml;
|
use externalfiles::ExternalHtml;
|
||||||
|
|
||||||
use serialize::json::{self, ToJson};
|
use serialize::json::as_json;
|
||||||
use syntax::{abi, ast};
|
use syntax::{abi, ast};
|
||||||
use syntax::feature_gate::UnstableFeatures;
|
use syntax::feature_gate::UnstableFeatures;
|
||||||
use rustc::middle::cstore::LOCAL_CRATE;
|
use rustc::middle::cstore::LOCAL_CRATE;
|
||||||
|
@ -534,8 +534,8 @@ pub fn run(mut krate: clean::Crate,
|
||||||
cx.krate(krate)
|
cx.krate(krate)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Build the search index from the collected metadata
|
||||||
fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
|
fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
|
||||||
// Build the search index from the collected metadata
|
|
||||||
let mut nodeid_to_pathid = HashMap::new();
|
let mut nodeid_to_pathid = HashMap::new();
|
||||||
let mut pathid_to_nodeid = Vec::new();
|
let mut pathid_to_nodeid = Vec::new();
|
||||||
{
|
{
|
||||||
|
@ -582,7 +582,13 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
|
||||||
|
|
||||||
// Collect the index into a string
|
// Collect the index into a string
|
||||||
let mut w = io::Cursor::new(Vec::new());
|
let mut w = io::Cursor::new(Vec::new());
|
||||||
write!(&mut w, r#"searchIndex['{}'] = {{"items":["#, krate.name).unwrap();
|
let krate_doc = krate.module.as_ref().map(|module| {
|
||||||
|
Escape(&shorter(module.doc_value())).to_string()
|
||||||
|
}).unwrap_or("".to_owned());
|
||||||
|
|
||||||
|
write!(&mut w, r#"searchIndex[{}] = {{doc: {}, "items":["#,
|
||||||
|
as_json(&krate.name),
|
||||||
|
as_json(&krate_doc)).unwrap();
|
||||||
|
|
||||||
let mut lastpath = "".to_string();
|
let mut lastpath = "".to_string();
|
||||||
for (i, item) in cache.search_index.iter().enumerate() {
|
for (i, item) in cache.search_index.iter().enumerate() {
|
||||||
|
@ -598,9 +604,9 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
write!(&mut w, ",").unwrap();
|
write!(&mut w, ",").unwrap();
|
||||||
}
|
}
|
||||||
write!(&mut w, r#"[{},"{}","{}",{}"#,
|
write!(&mut w, "[{},{},{},{}",
|
||||||
item.ty as usize, item.name, path,
|
item.ty as usize,
|
||||||
item.desc.to_json().to_string()).unwrap();
|
as_json(&item.name), as_json(&path), as_json(&item.desc)).unwrap();
|
||||||
match item.parent {
|
match item.parent {
|
||||||
Some(nodeid) => {
|
Some(nodeid) => {
|
||||||
let pathid = *nodeid_to_pathid.get(&nodeid).unwrap();
|
let pathid = *nodeid_to_pathid.get(&nodeid).unwrap();
|
||||||
|
@ -693,7 +699,7 @@ fn write_shared(cx: &Context,
|
||||||
if !line.starts_with(key) {
|
if !line.starts_with(key) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if line.starts_with(&format!("{}['{}']", key, krate)) {
|
if line.starts_with(&format!(r#"{}["{}"]"#, key, krate)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ret.push(line.to_string());
|
ret.push(line.to_string());
|
||||||
|
@ -1387,7 +1393,7 @@ impl Context {
|
||||||
let js_dst = this.dst.join("sidebar-items.js");
|
let js_dst = this.dst.join("sidebar-items.js");
|
||||||
let mut js_out = BufWriter::new(try_err!(File::create(&js_dst), &js_dst));
|
let mut js_out = BufWriter::new(try_err!(File::create(&js_dst), &js_dst));
|
||||||
try_err!(write!(&mut js_out, "initSidebarItems({});",
|
try_err!(write!(&mut js_out, "initSidebarItems({});",
|
||||||
json::as_json(&items)), &js_dst);
|
as_json(&items)), &js_dst);
|
||||||
}
|
}
|
||||||
|
|
||||||
for item in m.items {
|
for item in m.items {
|
||||||
|
|
|
@ -580,6 +580,9 @@
|
||||||
displayPath = "";
|
displayPath = "";
|
||||||
href = rootPath + item.path.replace(/::/g, '/') +
|
href = rootPath + item.path.replace(/::/g, '/') +
|
||||||
'/' + type + '.' + name + '.html';
|
'/' + type + '.' + name + '.html';
|
||||||
|
} else if (type === "externcrate") {
|
||||||
|
displayPath = "";
|
||||||
|
href = rootPath + name + '/index.html';
|
||||||
} else if (item.parent !== undefined) {
|
} else if (item.parent !== undefined) {
|
||||||
var myparent = item.parent;
|
var myparent = item.parent;
|
||||||
var anchor = '#' + type + '.' + name;
|
var anchor = '#' + type + '.' + name;
|
||||||
|
@ -678,6 +681,16 @@
|
||||||
for (var crate in rawSearchIndex) {
|
for (var crate in rawSearchIndex) {
|
||||||
if (!rawSearchIndex.hasOwnProperty(crate)) { continue; }
|
if (!rawSearchIndex.hasOwnProperty(crate)) { continue; }
|
||||||
|
|
||||||
|
searchWords.push(crate);
|
||||||
|
searchIndex.push({
|
||||||
|
crate: crate,
|
||||||
|
ty: 1, // == ExternCrate
|
||||||
|
name: crate,
|
||||||
|
path: "",
|
||||||
|
desc: rawSearchIndex[crate].doc,
|
||||||
|
type: null,
|
||||||
|
});
|
||||||
|
|
||||||
// an array of [(Number) item type,
|
// an array of [(Number) item type,
|
||||||
// (String) name,
|
// (String) name,
|
||||||
// (String) full path or empty string for previous path,
|
// (String) full path or empty string for previous path,
|
||||||
|
|
|
@ -82,7 +82,7 @@ pre {
|
||||||
}
|
}
|
||||||
|
|
||||||
.content a.primitive { color: #39a7bf; }
|
.content a.primitive { color: #39a7bf; }
|
||||||
.content span.mod, .content a.mod, block a.current.mod { color: #4d76ae; }
|
.content span.externcrate, span.mod, .content a.mod, block a.current.mod { color: #4d76ae; }
|
||||||
.content span.fn, .content a.fn, .block a.current.fn,
|
.content span.fn, .content a.fn, .block a.current.fn,
|
||||||
.content span.method, .content a.method, .block a.current.method,
|
.content span.method, .content a.method, .block a.current.method,
|
||||||
.content span.tymethod, .content a.tymethod, .block a.current.tymethod,
|
.content span.tymethod, .content a.tymethod, .block a.current.tymethod,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue