mirror of
https://github.com/alrayyes/wiki.git
synced 2024-11-22 19:46:23 +00:00
fix: jump to search for operand
This commit is contained in:
parent
f08a76a738
commit
e374e3abd4
4 changed files with 19 additions and 15 deletions
|
@ -56,6 +56,6 @@
|
||||||
}
|
}
|
||||||
const allIds = new Set([...getByField("title"), ...getByField("content")])
|
const allIds = new Set([...getByField("title"), ...getByField("content")])
|
||||||
const finalResults = [...allIds].map(formatForDisplay)
|
const finalResults = [...allIds].map(formatForDisplay)
|
||||||
displayResults(finalResults, true)
|
displayResults(term, finalResults, true)
|
||||||
})
|
})
|
||||||
})()
|
})()
|
||||||
|
|
|
@ -24,7 +24,7 @@ async function searchContents(query) {
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
query: query,
|
query: query,
|
||||||
limit: 8,
|
limit: 10,
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
if (result.ok) {
|
if (result.ok) {
|
||||||
|
@ -48,7 +48,7 @@ registerHandlers(
|
||||||
debounce((e) => {
|
debounce((e) => {
|
||||||
let term = e.target.value
|
let term = e.target.value
|
||||||
if (term !== "") {
|
if (term !== "") {
|
||||||
searchContents(term).then((results) => displayResults(results))
|
searchContents(term).then((results) => displayResults(term, results))
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
|
@ -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">
|
||||||
|
|
|
@ -79,6 +79,8 @@
|
||||||
"indices/contentIndex.json" | resources.Fingerprint "md5" | resources.Minify
|
"indices/contentIndex.json" | resources.Fingerprint "md5" | resources.Minify
|
||||||
}}
|
}}
|
||||||
<script>
|
<script>
|
||||||
|
const SEARCH_ENABLED = {{.Site.Data.config.search.enableSemanticSearch}}
|
||||||
|
const PRODUCTION = {{ hugo.IsProduction }}
|
||||||
const BASE_URL = {{.Site.BaseURL}}
|
const BASE_URL = {{.Site.BaseURL}}
|
||||||
const fetchData = Promise.all([
|
const fetchData = Promise.all([
|
||||||
fetch("{{ $linkIndex.Permalink }}")
|
fetch("{{ $linkIndex.Permalink }}")
|
||||||
|
|
Loading…
Reference in a new issue