Skip to content

Commit 5278949

Browse files
committed
Split search.js from search-index.js.
1 parent 11f854d commit 5278949

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

src/librustdoc/html/layout.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ crate fn render<T: Print, S: Print>(
113113
<section class=\"footer\"></section>\
114114
{after_content}\
115115
<div id=\"rustdoc-vars\" data-root-path=\"{root_path}\" data-current-crate=\"{krate}\" \
116-
data-search-js=\"{root_path}search-index{suffix}.js\"></div>
116+
data-search-index-js=\"{root_path}search-index{suffix}.js\" \
117+
data-search-js=\"{root_path}search{suffix}.js\"></div>
117118
<script src=\"{static_root_path}main{suffix}.js\"></script>\
118119
{extra_scripts}\
119120
</body>\

src/librustdoc/html/render/write_shared.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ pub(super) fn write_shared(
223223
&format!(" = {}", serde_json::to_string(&themes).unwrap()),
224224
),
225225
)?;
226+
write_minify("search.js", static_files::SEARCH_JS)?;
226227
write_minify("settings.js", static_files::SETTINGS_JS)?;
227228
if cx.shared.include_sources {
228229
write_minify("source-script.js", static_files::sidebar::SOURCE_SCRIPT)?;
@@ -408,8 +409,9 @@ pub(super) fn write_shared(
408409
// with rustdoc running in parallel.
409410
all_indexes.sort();
410411
write_crate("search-index.js", &|| {
411-
let v = static_files::SEARCH_JS
412-
.replace(r#""SEARCH_INDEX_PLACEHOLDER": {}"#, &all_indexes.join(",\\\n"));
412+
let mut v = String::from("var searchIndex = JSON.parse('{\\\n");
413+
v.push_str(&all_indexes.join(",\\\n"));
414+
v.push_str("\\\n}');\nif (window.initSearch) {window.initSearch(searchIndex)};");
413415
Ok(v.into_bytes())
414416
})?;
415417

src/librustdoc/html/static/main.js

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ if (!DOMTokenList.prototype.remove) {
4343
window.rootPath = rustdocVars.attributes["data-root-path"].value;
4444
window.currentCrate = rustdocVars.attributes["data-current-crate"].value;
4545
window.searchJS = rustdocVars.attributes["data-search-js"].value;
46+
window.searchIndexJS = rustdocVars.attributes["data-search-index-js"].value;
4647
}
4748
var sidebarVars = document.getElementById("sidebar-vars");
4849
if (sidebarVars) {
@@ -247,6 +248,7 @@ function hideThemeButtonState() {
247248
if (!searchLoaded) {
248249
searchLoaded = true;
249250
loadScript(window.searchJS);
251+
loadScript(window.searchIndexJS);
250252
}
251253
}
252254

src/librustdoc/html/static/search.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
(function() {
2-
var searchIndex = JSON.parse('{\
3-
"SEARCH_INDEX_PLACEHOLDER": {}\
4-
}');
5-
62
// This mapping table should match the discriminants of
73
// `rustdoc::html::item_type::ItemType` type in Rust.
84
var itemTypes = ["mod",
@@ -104,7 +100,7 @@ function levenshtein(s1, s2) {
104100
return s1_len + s2_len;
105101
}
106102

107-
function initSearch(rawSearchIndex) {
103+
window.initSearch = function(rawSearchIndex) {
108104
var MAX_LEV_DISTANCE = 3;
109105
var MAX_RESULTS = 200;
110106
var GENERICS_DATA = 1;
@@ -1509,6 +1505,8 @@ function initSearch(rawSearchIndex) {
15091505
}
15101506
};
15111507

1508+
if (window.searchIndex !== undefined) {
1509+
initSearch(window.searchIndex);
1510+
}
15121511

1513-
initSearch(searchIndex);
15141512
})();

0 commit comments

Comments
 (0)