Content collections: ignored underscore directories in file glob (#7268)

* fix: ignored underscore dirs in glob

* chore: changeset
This commit is contained in:
Ben Holmes 2023-06-02 07:54:50 -04:00 committed by GitHub
parent 6533041ce0
commit 9e7366567e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 6 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fix: ignore `.json` files within content collection directories starting with an `_` underscore.

View file

@ -44,14 +44,21 @@ export function astroContentVirtualModPlugin({
) )
.replace('@@CONTENT_DIR@@', relContentDir) .replace('@@CONTENT_DIR@@', relContentDir)
.replace( .replace(
'@@CONTENT_ENTRY_GLOB_PATH@@', "'@@CONTENT_ENTRY_GLOB_PATH@@'",
// [!_] = ignore files starting with "_" JSON.stringify(globWithUnderscoresIgnored(relContentDir, contentEntryExts))
`${relContentDir}**/[!_]*${getExtGlob(contentEntryExts)}`
) )
.replace('@@DATA_ENTRY_GLOB_PATH@@', `${relContentDir}**/[!_]*${getExtGlob(dataEntryExts)}`)
.replace( .replace(
'@@RENDER_ENTRY_GLOB_PATH@@', "'@@DATA_ENTRY_GLOB_PATH@@'",
`${relContentDir}**/*${getExtGlob(/** Note: data collections excluded */ contentEntryExts)}` JSON.stringify(globWithUnderscoresIgnored(relContentDir, dataEntryExts))
)
.replace(
"'@@RENDER_ENTRY_GLOB_PATH@@'",
JSON.stringify(
globWithUnderscoresIgnored(
relContentDir,
/** Note: data collections excluded */ contentEntryExts
)
)
); );
const astroContentVirtualModuleId = '\0' + VIRTUAL_MODULE_ID; const astroContentVirtualModuleId = '\0' + VIRTUAL_MODULE_ID;
@ -189,3 +196,8 @@ const UnexpectedLookupMapError = new AstroError({
...AstroErrorData.UnknownContentCollectionError, ...AstroErrorData.UnknownContentCollectionError,
message: `Unexpected error while parsing content entry IDs and slugs.`, message: `Unexpected error while parsing content entry IDs and slugs.`,
}); });
function globWithUnderscoresIgnored(relContentDir: string, exts: string[]): string[] {
const extGlob = getExtGlob(exts);
return [`${relContentDir}/**/*${extGlob}`, `!**/_*/**${extGlob}`, `!**/_*${extGlob}`];
}