diff options
| author | Serghei Iakovlev <egrep@protonmail.ch> | 2022-07-16 22:39:34 +0200 |
|---|---|---|
| committer | Serghei Iakovlev <egrep@protonmail.ch> | 2022-07-16 22:39:34 +0200 |
| commit | a516af25e13783b622dd54e1fd6ef149eacf2988 (patch) | |
| tree | fc93c85e6e1345a08861080b5a44933420af57f5 | |
| parent | 624fcebe7758611fd9051d286daa362d72cc873f (diff) | |
| download | gohugo-theme-ed-a516af25e13783b622dd54e1fd6ef149eacf2988.tar.gz | |
Make search constants in a local scope
| -rw-r--r-- | assets/js/search.js | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/assets/js/search.js b/assets/js/search.js index 7fd4d52..ff092d9 100644 --- a/assets/js/search.js +++ b/assets/js/search.js @@ -2,17 +2,6 @@ import {searchConfig, i18n} from '@params'; let pagesIndex, searchIndex; -// Since the blurb is comprised of full sentences containing any search -// term, we need a way to identify where each sentence begins/ends. This -// regex will be used to produce a list of all sentences from the page -// content. -const SENTENCE_BOUNDARY_REGEX = /\b\.\s/gm; - -// This is a simple regex that produces a list of words from the text -// it is applied to. This will be used to check the number of total words -// in the blurb as it is being built. -const WORD_REGEX = /\b(\w*)[\W|\s|\b]?/gm; - async function initSearchIndex() { try { const response = await fetch(searchConfig.indexURI); @@ -161,6 +150,12 @@ function createSearchResultBlurb(query, pageContent) { (m) => m.index ); + // Since the blurb is comprised of full sentences containing any search + // term, we need a way to identify where each sentence begins/ends. This + // regex will be used to produce a list of all sentences from the page + // content. + const SENTENCE_BOUNDARY_REGEX = /\b\.\s/gm; + const sentenceBoundaries = Array.from( pageContent.matchAll(SENTENCE_BOUNDARY_REGEX), (m) => m.index @@ -201,6 +196,11 @@ function createQueryStringRegex(query) { } function tokenize(input) { + // This is a simple regex that produces a list of words from the text + // it is applied to. This will be used to check the number of total words + // in the blurb as it is being built. + const WORD_REGEX = /\b(\w*)[\W|\s|\b]?/gm; + const wordMatches = Array.from(input.matchAll(WORD_REGEX), (m) => m); return wordMatches.map((m) => ({ word: m[0], |
