Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix search not showing in sub-directories #2586

Merged
merged 1 commit into from
Mar 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/theme/searcher/searcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,12 +468,12 @@ window.search = window.search || {};
showResults(true);
}

fetch('{{ resource "searchindex.json" }}')
fetch(path_to_root + '{{ resource "searchindex.json" }}')
.then(response => response.json())
.then(json => init(json))
.catch(error => { // Try to load searchindex.js if fetch failed
var script = document.createElement('script');
script.src = '{{ resource "searchindex.js" }}';
script.src = path_to_root + '{{ resource "searchindex.js" }}';
script.onload = () => init(window.search);
document.head.appendChild(script);
});
Expand Down
33 changes: 33 additions & 0 deletions tests/gui/search.goml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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"

define-function: (
"open-search",
[],
block {
assert-css: ("#search-wrapper", {"display": "none"})
press-key: 'S'
wait-for-css-false: ("#search-wrapper", {"display": "none"})
}
)

call-function: ("open-search", {})
assert-text: ("#searchresults-header", "")
write: "strikethrough"
wait-for-text: ("#searchresults-header", "2 search results for 'strikethrough':")
// Close the search display
press-key: 'Escape'
wait-for-css: ("#search-wrapper", {"display": "none"})
// Reopening the search should show the last value
call-function: ("open-search", {})
assert-text: ("#searchresults-header", "2 search results for 'strikethrough':")
// Navigate to a sub-chapter
go-to: "./individual/strikethrough.html"
assert-text: ("#searchresults-header", "")
call-function: ("open-search", {})
write: "strikethrough"
wait-for-text: ("#searchresults-header", "2 search results for 'strikethrough':")