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