merge search branch into redesign

This commit is contained in:
taskylizard 2025-07-04 11:18:29 +00:00
parent c7153b6739
commit 5bbdf245ae
No known key found for this signature in database
GPG key ID: 1820131ED1A24120
7 changed files with 1532 additions and 35 deletions

View file

@ -1,5 +1,6 @@
import type { DefaultTheme } from 'vitepress'
import consola from 'consola'
import { customTokenize, customTokenProcessor } from './search'
import { transform, transformGuide } from '../../website/transformer'
// @unocss-include
@ -49,44 +50,13 @@ export const search: DefaultTheme.Config['search'] = {
},
miniSearch: {
options: {
tokenize: (text) => text.split(/[\n\r #%*,=/:;?[\]{}()&]+/u), // simplified charset: removed [-_.@] and non-english chars (diacritics etc.)
processTerm: (term, fieldName) => {
// biome-ignore lint/style/noParameterAssign: h
term = term
.trim()
.toLowerCase()
.replace(/^\.+/, '')
.replace(/\.+$/, '')
const stopWords = [
'frontmatter',
'$frontmatter.synopsis',
'and',
'about',
'but',
'now',
'the',
'with',
'you'
]
if (term.length < 2 || stopWords.includes(term)) return false
if (fieldName === 'text') {
const parts = term.split('.')
if (parts.length > 1) {
const newTerms = [term, ...parts]
.filter((t) => t.length >= 2)
.filter((t) => !stopWords.includes(t))
return newTerms
}
}
return term
}
tokenize: customTokenize,
processTerm: customTokenProcessor
},
searchOptions: {
combineWith: 'AND',
fuzzy: true,
// @ts-ignore
boostDocument: (documentId, term, storedFields: Record) => {
console.log(storedFields.titles)
const titles = (storedFields?.titles as string[])
.filter((t) => Boolean(t))
.map((t) => t.toLowerCase())