diff --git a/assets/js/full-text-search.js b/assets/js/full-text-search.js index a8f7f23c6..108db1099 100644 --- a/assets/js/full-text-search.js +++ b/assets/js/full-text-search.js @@ -56,6 +56,6 @@ } const allIds = new Set([...getByField("title"), ...getByField("content")]) const finalResults = [...allIds].map(formatForDisplay) - displayResults(finalResults, true) + displayResults(term, finalResults, true) }) })() diff --git a/assets/js/semantic-search.js b/assets/js/semantic-search.js index bfe102e0b..fca2851eb 100644 --- a/assets/js/semantic-search.js +++ b/assets/js/semantic-search.js @@ -24,7 +24,7 @@ async function searchContents(query) { }, body: JSON.stringify({ query: query, - limit: 8, + limit: 10, }), }) if (result.ok) { @@ -48,7 +48,7 @@ registerHandlers( debounce((e) => { let term = e.target.value if (term !== "") { - searchContents(term).then((results) => displayResults(results)) + searchContents(term).then((results) => displayResults(term, results)) } }), ) diff --git a/assets/js/util.js b/assets/js/util.js index 06db3c1b7..d17594ae2 100644 --- a/assets/js/util.js +++ b/assets/js/util.js @@ -115,9 +115,11 @@ const resultToHTML = ({ url, title, content }) => { } const redir = (id, term) => { - // SPA navigation + const shouldTrim = PRODUCTION && SEARCH_ENABLED + const baseURLPrefix = shouldTrim ? "" : BASE_URL.replace(/\/$/g, "") + const urlString = `${baseURLPrefix}${id}#:~:text=${encodeURIComponent(term)}/` window.Million.navigate( - new URL(`${BASE_URL.replace(/\/$/g, "")}${id}#:~:text=${encodeURIComponent(term)}/`), + new URL(urlString), ".singlePage", ) closeSearch() @@ -179,7 +181,7 @@ const registerHandlers = (onInputFn) => { }) } -const displayResults = (finalResults, extractHighlight = false) => { +const displayResults = (term, finalResults, extractHighlight = false) => { const results = document.getElementById("results-container") if (finalResults.length === 0) { results.innerHTML = `