fix: expand fuse.js search to all pages (#586)

* fix(search): expand fuse.js search to all pages

* feat: allow custom fuse list glob pattern

---------

Co-authored-by: YunYouJun <me@yunyoujun.cn>
This commit is contained in:
MadDogOwner 2025-07-21 20:09:52 +08:00 committed by GitHub
parent 2259edb091
commit 155364bfc4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 1 deletions

View File

@ -33,6 +33,10 @@ export default defineSiteConfig({
type: 'fuse',
},
fuse: {
/**
* 设置搜索的文件路径
*/
// pattern: 'pages/**/*.md',
options: {
keys: ['title', 'tags', 'categories', 'excerpt', 'content'],
/**

View File

@ -21,7 +21,8 @@ import { setEnvProd } from '../utils/env'
export async function generateFuseList(options: ResolvedValaxyOptions) {
consola.start(`Generate List for Fuse Search by (${colors.cyan('fuse.js')}) ...`)
// generate
const files = await fg(`${options.userRoot}/pages/posts/**/*.md`)
const pattern = options.config.siteConfig.fuse.pattern || path.join(options.userRoot, 'pages/**/*.md')
const files = await fg(pattern)
const posts: FuseListItem[] = []
for await (const i of files) {

View File

@ -180,6 +180,14 @@ export interface SiteConfig {
* @description
*/
dataPath: string
/**
* fast-glob pattern to match Fuse List Data
* @default `pages\/**\/*.md`
* ```ts
* await fg(`${userRoot}/pages/posts/**\/*.md`)
* ```
*/
pattern?: string
/**
* @see https://fusejs.io/api/options.html
*/