| | |
| | | <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> |
| | |
| | | tokenize: "reverse", |
| | | charset: "latin:extra", |
| | | suggest: true, |
| | | cache: 10, |
| | | }) |
| | | |
| | | const scrapedContent = {{$.Site.Data.contentIndex}} |
| | |
| | | } |
| | | |
| | | 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) |
| | |
| | | } |
| | | |
| | | 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}"> |
| | |
| | | </button>` |
| | | } |
| | | |
| | | const redir = (id, term) => { |
| | | window.location.href = "{{.Site.BaseURL}}" + `${id}#:~:text=${encodeURIComponent(term)}` |
| | | } |
| | | |
| | | const source = document.getElementById('search-bar') |
| | | const results = document.getElementById("results-container") |
| | | let term |
| | | source.addEventListener("keyup", (e) => { |
| | | if (e.key === "Enter") { |
| | | const anchor = document.getElementsByClassName("result-card")[0] |
| | | window.location.href = `${anchor.id}#:~:text=${encodeURIComponent(term)}` |
| | | redir(anchor.id, term) |
| | | } |
| | | }) |
| | | 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)] |
| | |
| | | .join("\n") |
| | | const anchors = document.getElementsByClassName("result-card"); |
| | | [...anchors].forEach(anchor => { |
| | | anchor.onclick = () => { |
| | | window.location.href = `${anchor.id}#:~:text=${encodeURIComponent(term)}` |
| | | } |
| | | anchor.onclick = () => redir(anchor.id, term) |
| | | }) |
| | | } |
| | | }) |
| | |
| | | |
| | | |
| | | const searchContainer = document.getElementById("search-container") |
| | | |
| | | function openSearch() { |
| | | if (searchContainer.style.display === "none" || searchContainer.style.display === "") { |
| | | source.value = "" |