diff options
| author | Serghei Iakovlev <egrep@protonmail.ch> | 2022-07-16 23:35:08 +0200 |
|---|---|---|
| committer | Serghei Iakovlev <egrep@protonmail.ch> | 2022-07-16 23:35:08 +0200 |
| commit | 5388ad6ea170b9224819bd5e6802b636a0931619 (patch) | |
| tree | bca94a076e286dcf4903ddd6c544cfd216431b55 /assets | |
| parent | 1210306d64fdc7b05e06c6fdb8158f8473d589f7 (diff) | |
| download | gohugo-theme-ed-5388ad6ea170b9224819bd5e6802b636a0931619.tar.gz | |
Improve code style
Diffstat (limited to 'assets')
| -rw-r--r-- | assets/js/search.js | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/assets/js/search.js b/assets/js/search.js index ff092d9..e964358 100644 --- a/assets/js/search.js +++ b/assets/js/search.js @@ -145,19 +145,19 @@ function createSearchResultBlurb(query, pageContent) { // i: Case-insensitive search const searchQueryRegex = new RegExp(createQueryStringRegex(query), 'gmi'); - const searchQueryHits = Array.from( - pageContent.matchAll(searchQueryRegex), - (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 sentenceBoundaryRegex = /\b\.\s/gm; + + const searchQueryHits = Array.from( + pageContent.matchAll(searchQueryRegex), + (m) => m.index + ); const sentenceBoundaries = Array.from( - pageContent.matchAll(SENTENCE_BOUNDARY_REGEX), + pageContent.matchAll(sentenceBoundaryRegex), (m) => m.index ); @@ -199,9 +199,9 @@ 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 wordRegex = /\b(\w*)[\W|\s|\b]?/gm; - const wordMatches = Array.from(input.matchAll(WORD_REGEX), (m) => m); + const wordMatches = Array.from(input.matchAll(wordRegex), (m) => m); return wordMatches.map((m) => ({ word: m[0], start: m.index, |
