Skip to content

Commit

Permalink
style: fix linter
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed Nov 18, 2024
1 parent 11b3b08 commit d283cbf
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 25 deletions.
4 changes: 2 additions & 2 deletions plugins/search/plugin-slimsearch/src/client/worker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { getResults } from './result.js'
import { getSuggestions } from './suggestion.js'

self.onmessage = async ({
data: { type = 'all', query, locale, options, id },
data: { type = 'all', query, locale = '/', options, id },
}: MessageEvent<MessageData>): Promise<void> => {
const { default: localeIndex } = await database[locale ?? '/']()
const { default: localeIndex } = await database[locale]()

const searchLocaleIndex = loadJSONIndex<string, IndexItem, IndexItem>(
localeIndex,
Expand Down
34 changes: 15 additions & 19 deletions plugins/search/plugin-slimsearch/src/client/worker/matchContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,29 @@ export const getMatchedContent = (
let startIndex = 0
let contentLength = 0

const addResult = (content: string, isEnd = false): void => {
let text = ''
const addResult = (text: string, isEnd = false): void => {
let display: string

// A beginning of a long string
if (contentLength === 0)
text =
content.length > SUFFIX_LENGTH
? `… ${content.slice(-SUFFIX_LENGTH)}`
: content
display =
text.length > SUFFIX_LENGTH ? `… ${text.slice(-SUFFIX_LENGTH)}` : text
// Already the last text
else if (isEnd)
text =
display =
// If the string will be longer than maxLength
content.length + contentLength > MAX_LENGTH
? `${content.slice(0, MAX_LENGTH - contentLength)}… `
: content
text.length + contentLength > MAX_LENGTH
? `${text.slice(0, MAX_LENGTH - contentLength)}… `
: text
// Text is at the middle
else
text =
content.length > SUFFIX_LENGTH
? `${content.slice(0, SUFFIX_LENGTH)}${content.slice(
-SUFFIX_LENGTH,
)}`
: content

if (text) result.push(text)
contentLength += text.length
display =
text.length > SUFFIX_LENGTH
? `${text.slice(0, SUFFIX_LENGTH)}${text.slice(-SUFFIX_LENGTH)}`
: text

if (display) result.push(display)
contentLength += display.length

if (!isEnd) {
result.push(['mark', queryString])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ Sample text here...
Syntax highlighting:

```js
const foo = function (bar) {
return bar++
function foo(bar) {
return `foo${bar}`
}

console.log(foo(5))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ exports[`generateIndex > Should generate full index 2`] = `
"Block code:",
"Sample text here... ",
"Syntax highlighting:",
"const foo = function (bar) { return bar++ } console.log(foo(5)) ",
"function foo(bar) { return \`foo\${bar}\` } console.log(foo(5)) ",
],
},
]
Expand Down Expand Up @@ -755,7 +755,7 @@ exports[`generateIndex > Should support customFields with full index 2`] = `
"Block code:",
"Sample text here... ",
"Syntax highlighting:",
"const foo = function (bar) { return bar++ } console.log(foo(5)) ",
"function foo(bar) { return \`foo\${bar}\` } console.log(foo(5)) ",
],
},
]
Expand Down

0 comments on commit d283cbf

Please sign in to comment.