Skip to content

Commit

Permalink
Format javascript
Browse files Browse the repository at this point in the history
Fix formatting inconsistencies using standard.

Move getTermMatcher function up so that functions read in order of call
  • Loading branch information
lookupdaily committed Feb 8, 2023
1 parent e6f8ec7 commit e148669
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/assets/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@
const getExcerpt = (content, searchQuery) => {
const fullSearchTerm = getTermMatcher(searchQuery, content)
const searchTerms = searchQuery
.split(" ")
.split(' ')
.filter((i) => i)
.map((term) => getTermMatcher(term, content));
.map((term) => getTermMatcher(term, content))

const firstMatchedTerm = fullSearchTerm.matchIndex !== -1 ? fullSearchTerm : searchTerms.find(term => term.matchIndex !== -1)
const matchIndex = firstMatchedTerm ? firstMatchedTerm.matchIndex : 100
Expand All @@ -124,6 +124,11 @@
return excerpt
}

const getTermMatcher = (term, content) => {
const regex = new RegExp(term, 'ig')
return { term, regex, matchIndex: content.search(regex) }
}

const getStartIndex = (matchIndex, content) => {
let startIndex = Math.max(matchIndex - 100, 0)

Expand All @@ -148,11 +153,6 @@
return endIndex
}

const getTermMatcher = (term, content) => {
const regex = new RegExp(term, 'ig')
return { term, regex, matchIndex: content.search(regex) }
}

const setHeading = (resultsCount, searchQuery) => {
const searchHeading = document.getElementById('search-heading')

Expand Down

0 comments on commit e148669

Please sign in to comment.