Split search.js from search-index.js.
This commit is contained in:
parent
11f854db4f
commit
52789498e9
@ -113,7 +113,8 @@ crate fn render<T: Print, S: Print>(
|
||||
<section class=\"footer\"></section>\
|
||||
{after_content}\
|
||||
<div id=\"rustdoc-vars\" data-root-path=\"{root_path}\" data-current-crate=\"{krate}\" \
|
||||
data-search-js=\"{root_path}search-index{suffix}.js\"></div>
|
||||
data-search-index-js=\"{root_path}search-index{suffix}.js\" \
|
||||
data-search-js=\"{root_path}search{suffix}.js\"></div>
|
||||
<script src=\"{static_root_path}main{suffix}.js\"></script>\
|
||||
{extra_scripts}\
|
||||
</body>\
|
||||
|
@ -223,6 +223,7 @@ pub(super) fn write_shared(
|
||||
&format!(" = {}", serde_json::to_string(&themes).unwrap()),
|
||||
),
|
||||
)?;
|
||||
write_minify("search.js", static_files::SEARCH_JS)?;
|
||||
write_minify("settings.js", static_files::SETTINGS_JS)?;
|
||||
if cx.shared.include_sources {
|
||||
write_minify("source-script.js", static_files::sidebar::SOURCE_SCRIPT)?;
|
||||
@ -408,8 +409,9 @@ pub(super) fn write_shared(
|
||||
// with rustdoc running in parallel.
|
||||
all_indexes.sort();
|
||||
write_crate("search-index.js", &|| {
|
||||
let v = static_files::SEARCH_JS
|
||||
.replace(r#""SEARCH_INDEX_PLACEHOLDER": {}"#, &all_indexes.join(",\\\n"));
|
||||
let mut v = String::from("var searchIndex = JSON.parse('{\\\n");
|
||||
v.push_str(&all_indexes.join(",\\\n"));
|
||||
v.push_str("\\\n}');\nif (window.initSearch) {window.initSearch(searchIndex)};");
|
||||
Ok(v.into_bytes())
|
||||
})?;
|
||||
|
||||
|
@ -43,6 +43,7 @@ if (!DOMTokenList.prototype.remove) {
|
||||
window.rootPath = rustdocVars.attributes["data-root-path"].value;
|
||||
window.currentCrate = rustdocVars.attributes["data-current-crate"].value;
|
||||
window.searchJS = rustdocVars.attributes["data-search-js"].value;
|
||||
window.searchIndexJS = rustdocVars.attributes["data-search-index-js"].value;
|
||||
}
|
||||
var sidebarVars = document.getElementById("sidebar-vars");
|
||||
if (sidebarVars) {
|
||||
@ -247,6 +248,7 @@ function hideThemeButtonState() {
|
||||
if (!searchLoaded) {
|
||||
searchLoaded = true;
|
||||
loadScript(window.searchJS);
|
||||
loadScript(window.searchIndexJS);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,4 @@
|
||||
(function() {
|
||||
var searchIndex = JSON.parse('{\
|
||||
"SEARCH_INDEX_PLACEHOLDER": {}\
|
||||
}');
|
||||
|
||||
// This mapping table should match the discriminants of
|
||||
// `rustdoc::html::item_type::ItemType` type in Rust.
|
||||
var itemTypes = ["mod",
|
||||
@ -104,7 +100,7 @@ function levenshtein(s1, s2) {
|
||||
return s1_len + s2_len;
|
||||
}
|
||||
|
||||
function initSearch(rawSearchIndex) {
|
||||
window.initSearch = function(rawSearchIndex) {
|
||||
var MAX_LEV_DISTANCE = 3;
|
||||
var MAX_RESULTS = 200;
|
||||
var GENERICS_DATA = 1;
|
||||
@ -1509,6 +1505,8 @@ function initSearch(rawSearchIndex) {
|
||||
}
|
||||
};
|
||||
|
||||
if (window.searchIndex !== undefined) {
|
||||
initSearch(window.searchIndex);
|
||||
}
|
||||
|
||||
initSearch(searchIndex);
|
||||
})();
|
||||
|
Loading…
x
Reference in New Issue
Block a user