2023-11-08 19:32:02 +00:00
|
|
|
import Fuse, { FuseIndexRecords } from 'fuse.js'
|
2022-10-01 20:32:01 +00:00
|
|
|
import { getConfigSettings, getLua, getVariables } from './doc-utils'
|
|
|
|
export interface SearchItem {
|
|
|
|
kind: string
|
|
|
|
name: string
|
|
|
|
desc: string
|
|
|
|
}
|
|
|
|
export interface SearchIndex {
|
|
|
|
index: {
|
|
|
|
keys: readonly string[]
|
2023-11-08 19:32:02 +00:00
|
|
|
records: FuseIndexRecords
|
2022-10-01 20:32:01 +00:00
|
|
|
}
|
|
|
|
list: SearchItem[]
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getSearchIndex() {
|
|
|
|
const cs: SearchItem[] = getConfigSettings().values.map((v) => ({
|
|
|
|
kind: 'config',
|
|
|
|
name: v.name,
|
2022-10-05 03:37:40 +00:00
|
|
|
desc: v.desc.substring(0, 121),
|
2022-10-01 20:32:01 +00:00
|
|
|
}))
|
|
|
|
const vars: SearchItem[] = getVariables().values.map((v) => ({
|
|
|
|
kind: 'var',
|
|
|
|
name: v.name,
|
2022-10-05 03:37:40 +00:00
|
|
|
desc: v.desc.substring(0, 121),
|
2022-10-01 20:32:01 +00:00
|
|
|
}))
|
|
|
|
const lua: SearchItem[] = getLua().values.map((v) => ({
|
|
|
|
kind: 'lua',
|
|
|
|
name: v.name,
|
2022-10-05 03:37:40 +00:00
|
|
|
desc: v.desc.substring(0, 121),
|
2022-10-01 20:32:01 +00:00
|
|
|
}))
|
|
|
|
const list: SearchItem[] = [...cs, ...vars, ...lua]
|
|
|
|
|
|
|
|
return {
|
2022-10-05 03:37:40 +00:00
|
|
|
list,
|
2022-10-01 20:32:01 +00:00
|
|
|
index: Fuse.createIndex<SearchItem>(['name', 'desc'], list).toJSON(),
|
|
|
|
}
|
|
|
|
}
|