Skip to content

Commit bddd834

Browse files
committed
fix(preview): take exclude into account to find collection
1 parent 37d3008 commit bddd834

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/runtime/internal/preview/collection.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const getCollectionByFilePath = (path: string, collections: Record<string
1616
const pathWithoutRoot = withoutRoot(path)
1717
const paths = pathWithoutRoot === '/' ? ['index.yml', 'index.yaml', 'index.md', 'index.json'] : [pathWithoutRoot]
1818
return paths.some((p) => {
19-
matchedSource = collection.source.find(source => minimatch(p, source.include))
19+
matchedSource = collection.source.find(source => minimatch(p, source.include) && !source.exclude?.some(exclude => minimatch(p, exclude)))
2020
return matchedSource
2121
})
2222
})
@@ -43,7 +43,7 @@ export const getCollectionByRoutePath = (routePath: string, collections: Record<
4343
const indexFiles = ['index.yml', 'index.yaml', 'index.md', 'index.json']
4444
const files = routePath === '/' ? indexFiles : indexFiles.map(file => withoutLeadingSlash(joinURL(source.prefix, file)))
4545
return files.some((p) => {
46-
return collection.source.find(source => minimatch(p, source.include))
46+
return collection.source.find(source => minimatch(p, source.include) && !source.exclude?.some(exclude => minimatch(p, exclude)))
4747
})
4848
}
4949

@@ -53,10 +53,11 @@ export const getCollectionByRoutePath = (routePath: string, collections: Record<
5353

5454
const path = joinURL(fixed, pathWithoutPrefix)
5555

56-
// Remove extension from source.include
57-
const pattern = source.include.replace(/\.[^/.]+$/, '')
56+
const removeExtension = (pattern: string) => {
57+
return pattern.replace(/\.[^/.]+$/, '')
58+
}
5859

59-
return minimatch(path, pattern)
60+
return minimatch(path, removeExtension(source.include)) && !source.exclude?.some(exclude => minimatch(path, removeExtension(exclude)))
6061
})
6162

6263
return matchedSource

0 commit comments

Comments
 (0)