feat: allow custom fuse list glob pattern

This commit is contained in:
YunYouJun 2025-07-21 20:09:14 +08:00
parent 58e30a3a33
commit d3c4657142
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/**/*.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
*/