|
|
|
@ -59,26 +59,20 @@ const removeMarkdown = (
|
|
|
|
|
// -----
|
|
|
|
|
|
|
|
|
|
(async function() {
|
|
|
|
|
const encoder = str => str.toLowerCase().split(/([^a-z]|[^\x00-\x7F])+/)
|
|
|
|
|
const contentIndex = new FlexSearch.Document({
|
|
|
|
|
cache: true,
|
|
|
|
|
charset: "latin:extra",
|
|
|
|
|
optimize: true,
|
|
|
|
|
worker: true,
|
|
|
|
|
document: {
|
|
|
|
|
index: [{
|
|
|
|
|
field: "content",
|
|
|
|
|
tokenize: "strict",
|
|
|
|
|
context: {
|
|
|
|
|
resolution: 5,
|
|
|
|
|
depth: 3,
|
|
|
|
|
bidirectional: true
|
|
|
|
|
},
|
|
|
|
|
suggest: true,
|
|
|
|
|
tokenize: "reverse",
|
|
|
|
|
encode: encoder,
|
|
|
|
|
}, {
|
|
|
|
|
field: "title",
|
|
|
|
|
tokenize: "forward",
|
|
|
|
|
encode: encoder,
|
|
|
|
|
}]
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const { content } = await fetchData
|
|
|
|
@ -158,17 +152,16 @@ const removeMarkdown = (
|
|
|
|
|
})
|
|
|
|
|
source.addEventListener('input', (e) => {
|
|
|
|
|
term = e.target.value
|
|
|
|
|
contentIndex.search(term, [
|
|
|
|
|
const searchResults = contentIndex.search(term, [
|
|
|
|
|
{
|
|
|
|
|
field: "content",
|
|
|
|
|
limit: 10,
|
|
|
|
|
suggest: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
field: "title",
|
|
|
|
|
limit: 5,
|
|
|
|
|
}
|
|
|
|
|
]).then(searchResults => {
|
|
|
|
|
])
|
|
|
|
|
const getByField = field => {
|
|
|
|
|
const results = searchResults.filter(x => x.field === field)
|
|
|
|
|
if (results.length === 0) {
|
|
|
|
@ -199,7 +192,6 @@ const removeMarkdown = (
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const searchContainer = document.getElementById("search-container")
|
|
|
|
@ -220,7 +212,7 @@ const removeMarkdown = (
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
document.addEventListener('keydown', (event) => {
|
|
|
|
|
if (event.key === "/") {
|
|
|
|
|
if (event.key === "k" && (event.ctrlKey || event.metaKey)) {
|
|
|
|
|
event.preventDefault()
|
|
|
|
|
openSearch()
|
|
|
|
|
}
|
|
|
|
|