|
|
@ -115,9 +115,11 @@ const resultToHTML = ({ url, title, content }) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const redir = (id, term) => {
|
|
|
|
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(
|
|
|
|
window.Million.navigate(
|
|
|
|
new URL(`${BASE_URL.replace(/\/$/g, "")}${id}#:~:text=${encodeURIComponent(term)}/`),
|
|
|
|
new URL(urlString),
|
|
|
|
".singlePage",
|
|
|
|
".singlePage",
|
|
|
|
)
|
|
|
|
)
|
|
|
|
closeSearch()
|
|
|
|
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")
|
|
|
|
const results = document.getElementById("results-container")
|
|
|
|
if (finalResults.length === 0) {
|
|
|
|
if (finalResults.length === 0) {
|
|
|
|
results.innerHTML = `<button class="result-card">
|
|
|
|
results.innerHTML = `<button class="result-card">
|
|
|
@ -189,16 +191,16 @@ const displayResults = (finalResults, extractHighlight = false) => {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
results.innerHTML = finalResults
|
|
|
|
results.innerHTML = finalResults
|
|
|
|
.map((result) => {
|
|
|
|
.map((result) => {
|
|
|
|
if (extractHighlight) {
|
|
|
|
if (extractHighlight) {
|
|
|
|
return resultToHTML({
|
|
|
|
return resultToHTML({
|
|
|
|
url: result.url,
|
|
|
|
url: result.url,
|
|
|
|
title: highlight(result.title, term),
|
|
|
|
title: highlight(result.title, term),
|
|
|
|
content: highlight(removeMarkdown(result.content), term)
|
|
|
|
content: highlight(removeMarkdown(result.content), term)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return resultToHTML(result)
|
|
|
|
return resultToHTML(result)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.join("\n")
|
|
|
|
.join("\n")
|
|
|
|
const anchors = [...document.getElementsByClassName("result-card")]
|
|
|
|
const anchors = [...document.getElementsByClassName("result-card")]
|
|
|
|