Skip to content

Commit

Permalink
search fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jackyzha0 committed Oct 25, 2021
1 parent 1835b97 commit f7b89db
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions layouts/partials/search.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<div id="search-container">
<div id="search-space">
<input autoComplete="off" id="search-bar" name="search" type="text" aria-label="Search"
placeholder="Search for something...">
<input autocomplete="off" id="search-bar" name="search" type="text" aria-label="Search" placeholder="Search for something...">
<div id="results-container">
</div>
</div>
Expand Down Expand Up @@ -72,6 +71,7 @@
tokenize: "reverse",
charset: "latin:extra",
suggest: true,
cache: 10,
})

const scrapedContent = {{$.Site.Data.contentIndex}}
Expand All @@ -80,10 +80,10 @@
}

const highlight = (content, term) => {
const highlightWindow = 15
const highlightWindow = 20
const tokenizedTerm = term.split(/\s+/).filter(t => t !== "")
const splitText = content.split(/\s+/).filter(t => t !== "")
const includesCheck = (token) => tokenizedTerm.some(term => token.toLowerCase().includes(term.toLowerCase()))
const includesCheck = (token) => tokenizedTerm.some(term => token.toLowerCase().startsWith(term.toLowerCase()))

const occurrencesIndices = splitText
.map(includesCheck)
Expand Down Expand Up @@ -116,8 +116,7 @@
}

const resultToHTML = ({url, title, content, term}) => {
const md = content.split("---")[2]
const text = removeMarkdown(md)
const text = removeMarkdown(content)
const resultTitle = highlight(title, term)
const resultText = highlight(text, term)
return `<button class="result-card" id="${url}">
Expand All @@ -142,8 +141,7 @@ <h3>${resultTitle}</h3>
source.addEventListener('input', (e) => {
term = e.target.value
contentIndex.search(term, {
limit: 20,
depth: 3,
limit: 15,
suggest: true,
}).then(searchResults => {
const resultIds = [...new Set(searchResults)]
Expand Down Expand Up @@ -175,7 +173,6 @@ <h3>${resultTitle}</h3>


const searchContainer = document.getElementById("search-container")

function openSearch() {
if (searchContainer.style.display === "none" || searchContainer.style.display === "") {
source.value = ""
Expand Down

0 comments on commit f7b89db

Please sign in to comment.