mirror of
https://github.com/fmhy/edit.git
synced 2025-08-03 09:42:14 +10:00
merge search branch into redesign
This commit is contained in:
parent
c7153b6739
commit
5bbdf245ae
7 changed files with 1532 additions and 35 deletions
|
@ -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())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue