diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2021-04-17 22:31:32 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-17 22:31:32 +0200 |
| commit | b5ce9c44a3137ee26a23228bc83cd8929438a3cf (patch) | |
| tree | 03195c4874a78d8e385b2228306fa0b405e2491e /src/librustdoc/html/render | |
| parent | 5dae27a8da16f352f82e93df691e7875bd360ea7 (diff) | |
| parent | 6f1f3eb516a433f4b32ab7298409015555b1cef6 (diff) | |
| download | rust-b5ce9c44a3137ee26a23228bc83cd8929438a3cf.tar.gz rust-b5ce9c44a3137ee26a23228bc83cd8929438a3cf.zip | |
Rollup merge of #84150 - jsha:defer-search-js, r=GuillaumeGomez
rustdoc: move some search code into search.js This reduces main.s from 3094 lines to 1587. Also it saves some bytes of download in the case where search isn't used. There were a fair number of variables that needed to be accessible in both main.js and search.js, but I didn't want to put too many symbols in the global namespace, so I consolidated much of the search-related state and functions into a new object `window.searchState`. Demo at https://hoffman-andrews.com/rust/move-search/std/?search=foo
Diffstat (limited to 'src/librustdoc/html/render')
| -rw-r--r-- | src/librustdoc/html/render/write_shared.rs | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/src/librustdoc/html/render/write_shared.rs b/src/librustdoc/html/render/write_shared.rs index 90e56d00a11..78bcd40af75 100644 --- a/src/librustdoc/html/render/write_shared.rs +++ b/src/librustdoc/html/render/write_shared.rs @@ -222,6 +222,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)?; @@ -409,7 +410,7 @@ pub(super) fn write_shared( write_crate("search-index.js", &|| { let mut v = String::from("var searchIndex = JSON.parse('{\\\n"); v.push_str(&all_indexes.join(",\\\n")); - v.push_str("\\\n}');\ninitSearch(searchIndex);"); + v.push_str("\\\n}');\nif (window.initSearch) {window.initSearch(searchIndex)};"); Ok(v.into_bytes()) })?; |
