From 8bb5426441c199335a8ee29e8333b6aba0eae82b Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 7 May 2019 15:29:46 -0700 Subject: [PATCH] Fix keyboard chapter navigation for `file` urls. (#915) --- src/renderer/html_handlebars/search.rs | 2 +- tests/rendered_output.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/renderer/html_handlebars/search.rs b/src/renderer/html_handlebars/search.rs index df7a698f..0531a232 100644 --- a/src/renderer/html_handlebars/search.rs +++ b/src/renderer/html_handlebars/search.rs @@ -35,7 +35,7 @@ pub fn create_files(search_config: &Search, destination: &Path, book: &Book) -> utils::fs::write_file( destination, "searchindex.js", - format!("window.search = {};", index).as_bytes(), + format!("Object.assign(window.search, {});", index).as_bytes(), )?; utils::fs::write_file(destination, "searcher.js", searcher::JS)?; utils::fs::write_file(destination, "mark.min.js", searcher::MARK_JS)?; diff --git a/tests/rendered_output.rs b/tests/rendered_output.rs index 8766ed88..3c9632a1 100644 --- a/tests/rendered_output.rs +++ b/tests/rendered_output.rs @@ -427,8 +427,8 @@ mod search { fn read_book_index(root: &Path) -> serde_json::Value { let index = root.join("book/searchindex.js"); let index = file_to_string(index).unwrap(); - let index = index.trim_start_matches("window.search = "); - let index = index.trim_end_matches(';'); + let index = index.trim_start_matches("Object.assign(window.search, "); + let index = index.trim_end_matches(");"); serde_json::from_str(&index).unwrap() }