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 serialize::json::{self, ToJson};
|
||||
use serialize::json::as_json;
|
||||
use syntax::{abi, ast};
|
||||
use syntax::feature_gate::UnstableFeatures;
|
||||
use rustc::middle::cstore::LOCAL_CRATE;
|
||||
|
@ -534,8 +534,8 @@ pub fn run(mut krate: clean::Crate,
|
|||
cx.krate(krate)
|
||||
}
|
||||
|
||||
/// Build the search index from the collected metadata
|
||||
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 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
|
||||
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();
|
||||
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 {
|
||||
write!(&mut w, ",").unwrap();
|
||||
}
|
||||
write!(&mut w, r#"[{},"{}","{}",{}"#,
|
||||
item.ty as usize, item.name, path,
|
||||
item.desc.to_json().to_string()).unwrap();
|
||||
write!(&mut w, "[{},{},{},{}",
|
||||
item.ty as usize,
|
||||
as_json(&item.name), as_json(&path), as_json(&item.desc)).unwrap();
|
||||
match item.parent {
|
||||
Some(nodeid) => {
|
||||
let pathid = *nodeid_to_pathid.get(&nodeid).unwrap();
|
||||
|
@ -693,7 +699,7 @@ fn write_shared(cx: &Context,
|
|||
if !line.starts_with(key) {
|
||||
continue
|
||||
}
|
||||
if line.starts_with(&format!("{}['{}']", key, krate)) {
|
||||
if line.starts_with(&format!(r#"{}["{}"]"#, key, krate)) {
|
||||
continue
|
||||
}
|
||||
ret.push(line.to_string());
|
||||
|
@ -1387,7 +1393,7 @@ impl Context {
|
|||
let js_dst = this.dst.join("sidebar-items.js");
|
||||
let mut js_out = BufWriter::new(try_err!(File::create(&js_dst), &js_dst));
|
||||
try_err!(write!(&mut js_out, "initSidebarItems({});",
|
||||
json::as_json(&items)), &js_dst);
|
||||
as_json(&items)), &js_dst);
|
||||
}
|
||||
|
||||
for item in m.items {
|
||||
|
|
|
@ -580,6 +580,9 @@
|
|||
displayPath = "";
|
||||
href = rootPath + item.path.replace(/::/g, '/') +
|
||||
'/' + type + '.' + name + '.html';
|
||||
} else if (type === "externcrate") {
|
||||
displayPath = "";
|
||||
href = rootPath + name + '/index.html';
|
||||
} else if (item.parent !== undefined) {
|
||||
var myparent = item.parent;
|
||||
var anchor = '#' + type + '.' + name;
|
||||
|
@ -678,6 +681,16 @@
|
|||
for (var crate in rawSearchIndex) {
|
||||
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,
|
||||
// (String) name,
|
||||
// (String) full path or empty string for previous path,
|
||||
|
|
|
@ -82,7 +82,7 @@ pre {
|
|||
}
|
||||
|
||||
.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.method, .content a.method, .block a.current.method,
|
||||
.content span.tymethod, .content a.tymethod, .block a.current.tymethod,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue