Merge pull request #2552 from GuillaumeGomez/deduplicate-search-indexes
Remove JSON search file
This commit is contained in:
commit
3ed302467e
6 changed files with 15 additions and 24 deletions
|
|
@ -60,11 +60,10 @@ pub fn create_files(
|
||||||
let index = write_to_json(index, search_config, doc_urls)?;
|
let index = write_to_json(index, search_config, doc_urls)?;
|
||||||
debug!("Writing search index ✓");
|
debug!("Writing search index ✓");
|
||||||
if index.len() > 10_000_000 {
|
if index.len() > 10_000_000 {
|
||||||
warn!("searchindex.json is very large ({} bytes)", index.len());
|
warn!("search index is very large ({} bytes)", index.len());
|
||||||
}
|
}
|
||||||
|
|
||||||
if search_config.copy_js {
|
if search_config.copy_js {
|
||||||
static_files.add_builtin("searchindex.json", index.as_bytes());
|
|
||||||
static_files.add_builtin(
|
static_files.add_builtin(
|
||||||
"searchindex.js",
|
"searchindex.js",
|
||||||
format!("Object.assign(window.search, {});", index).as_bytes(),
|
format!("Object.assign(window.search, {});", index).as_bytes(),
|
||||||
|
|
|
||||||
|
|
@ -441,7 +441,6 @@ window.search = window.search || {};
|
||||||
}
|
}
|
||||||
|
|
||||||
function doSearch(searchterm) {
|
function doSearch(searchterm) {
|
||||||
|
|
||||||
// Don't search the same twice
|
// Don't search the same twice
|
||||||
if (current_searchterm == searchterm) { return; }
|
if (current_searchterm == searchterm) { return; }
|
||||||
else { current_searchterm = searchterm; }
|
else { current_searchterm = searchterm; }
|
||||||
|
|
@ -468,15 +467,18 @@ window.search = window.search || {};
|
||||||
showResults(true);
|
showResults(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch(path_to_root + '{{ resource "searchindex.json" }}')
|
function loadScript(url, id) {
|
||||||
.then(response => response.json())
|
const script = document.createElement('script');
|
||||||
.then(json => init(json))
|
script.src = url;
|
||||||
.catch(error => { // Try to load searchindex.js if fetch failed
|
script.id = id;
|
||||||
var script = document.createElement('script');
|
|
||||||
script.src = path_to_root + '{{ resource "searchindex.js" }}';
|
|
||||||
script.onload = () => init(window.search);
|
script.onload = () => init(window.search);
|
||||||
document.head.appendChild(script);
|
script.onerror = error => {
|
||||||
});
|
console.error(`Failed to load \`${url}\`: ${error}`);
|
||||||
|
};
|
||||||
|
document.head.append(script);
|
||||||
|
}
|
||||||
|
|
||||||
|
loadScript(path_to_root + '{{ resource "searchindex.js" }}', 'search-index');
|
||||||
|
|
||||||
// Exported functions
|
// Exported functions
|
||||||
search.hasFocus = hasFocus;
|
search.hasFocus = hasFocus;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
// This tests pressing the left and right arrows moving to previous and next page.
|
// This tests pressing the left and right arrows moving to previous and next page.
|
||||||
|
|
||||||
// We disable the requests checks because `searchindex.json` will always fail
|
// We disable the requests checks because `mode-rust.js` is not found.
|
||||||
// locally (due to CORS), but the searchindex.js will succeed.
|
|
||||||
fail-on-request-error: false
|
fail-on-request-error: false
|
||||||
|
|
||||||
go-to: |DOC_PATH| + "index.html"
|
go-to: |DOC_PATH| + "index.html"
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,5 @@
|
||||||
// This tests basic search behavior.
|
// This tests basic search behavior.
|
||||||
|
|
||||||
// We disable the requests checks because `searchindex.json` will always fail
|
|
||||||
// locally (due to CORS), but the searchindex.js will succeed.
|
|
||||||
fail-on-request-error: false
|
|
||||||
go-to: |DOC_PATH| + "index.html"
|
go-to: |DOC_PATH| + "index.html"
|
||||||
|
|
||||||
define-function: (
|
define-function: (
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,6 @@
|
||||||
// an iframe (because of JS disabled).
|
// an iframe (because of JS disabled).
|
||||||
// Regression test for <https://github.com/rust-lang/mdBook/issues/2528>.
|
// Regression test for <https://github.com/rust-lang/mdBook/issues/2528>.
|
||||||
|
|
||||||
// We disable the requests checks because `searchindex.json` will always fail
|
|
||||||
// locally.
|
|
||||||
fail-on-request-error: false
|
|
||||||
// We disable javascript
|
// We disable javascript
|
||||||
javascript: false
|
javascript: false
|
||||||
go-to: |DOC_PATH| + "index.html"
|
go-to: |DOC_PATH| + "index.html"
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,6 @@
|
||||||
// This GUI test checks sidebar hide/show and also its behaviour on smaller
|
// This GUI test checks sidebar hide/show and also its behaviour on smaller
|
||||||
// width.
|
// width.
|
||||||
|
|
||||||
// We disable the requests checks because `searchindex.json` will always fail
|
|
||||||
// locally.
|
|
||||||
fail-on-request-error: false
|
|
||||||
go-to: |DOC_PATH| + "index.html"
|
go-to: |DOC_PATH| + "index.html"
|
||||||
set-window-size: (1100, 600)
|
set-window-size: (1100, 600)
|
||||||
// Need to reload for the new size to be taken account by the JS.
|
// Need to reload for the new size to be taken account by the JS.
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue