Skip to content

Commit 7a3e8e5

Browse files
committed
feat: search Add configurable search index URL
This commit introduces a configurable search index URL, allowing users to specify the location of the search index file via `window.searchIndexURL`. This improves flexibility and allows for easier deployment in different environments.
1 parent 44ec6c9 commit 7a3e8e5

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

assets/js/search.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@
1818
async function initFuse() {
1919
if (isFuseInitialized) return;
2020
try {
21-
const response = await fetch('/searchindex.json');
21+
if (!window.searchIndexURL) {
22+
throw new Error('Search index URL not provided via window.searchIndexURL');
23+
}
24+
const response = await fetch(window.searchIndexURL);
2225
if (!response.ok) {
23-
throw new Error('Search index not found');
26+
throw new Error('Search index not found at ' + window.searchIndexURL);
2427
}
2528
searchData = await response.json();
2629
const options = {

layouts/_default/baseof.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,8 @@ <h3 id="search-modal-title" class="text-xl font-bold">Search</h3>
8585
{{ end }}
8686
</body>
8787
</html>
88+
89+
<!-- Search Scripts -->
90+
<script>
91+
window.searchIndexURL = "{{ (site.Home.OutputFormats.Get `SearchIndex`).RelPermalink }}";
92+
</script>

0 commit comments

Comments
 (0)