summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Ben Holmes <hey@bholmes.dev> 2023-06-02 07:54:50 -0400
committerGravatar GitHub <noreply@github.com> 2023-06-02 07:54:50 -0400
commit9e7366567e2b83d46a46db35e74ad508d1978039 (patch)
treeffadb5792fe2af2f9253a7e8931e066290ebc4a5
parent6533041ce03ff68220afcae470a50b902cc15640 (diff)
downloadastro-9e7366567e2b83d46a46db35e74ad508d1978039.tar.gz
astro-9e7366567e2b83d46a46db35e74ad508d1978039.tar.zst
astro-9e7366567e2b83d46a46db35e74ad508d1978039.zip
Content collections: ignored underscore directories in file glob (#7268)
* fix: ignored underscore dirs in glob * chore: changeset
-rw-r--r--.changeset/rotten-pens-destroy.md5
-rw-r--r--packages/astro/src/content/vite-plugin-content-virtual-mod.ts24
2 files changed, 23 insertions, 6 deletions
diff --git a/.changeset/rotten-pens-destroy.md b/.changeset/rotten-pens-destroy.md
new file mode 100644
index 000000000..c8fb40872
--- /dev/null
+++ b/.changeset/rotten-pens-destroy.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+Fix: ignore `.json` files within content collection directories starting with an `_` underscore.
diff --git a/packages/astro/src/content/vite-plugin-content-virtual-mod.ts b/packages/astro/src/content/vite-plugin-content-virtual-mod.ts
index 838d6b425..bd516b199 100644
--- a/packages/astro/src/content/vite-plugin-content-virtual-mod.ts
+++ b/packages/astro/src/content/vite-plugin-content-virtual-mod.ts
@@ -44,14 +44,21 @@ export function astroContentVirtualModPlugin({
)
.replace('@@CONTENT_DIR@@', relContentDir)
.replace(
- '@@CONTENT_ENTRY_GLOB_PATH@@',
- // [!_] = ignore files starting with "_"
- `${relContentDir}**/[!_]*${getExtGlob(contentEntryExts)}`
+ "'@@CONTENT_ENTRY_GLOB_PATH@@'",
+ JSON.stringify(globWithUnderscoresIgnored(relContentDir, contentEntryExts))
)
- .replace('@@DATA_ENTRY_GLOB_PATH@@', `${relContentDir}**/[!_]*${getExtGlob(dataEntryExts)}`)
.replace(
- '@@RENDER_ENTRY_GLOB_PATH@@',
- `${relContentDir}**/*${getExtGlob(/** Note: data collections excluded */ contentEntryExts)}`
+ "'@@DATA_ENTRY_GLOB_PATH@@'",
+ 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;
@@ -189,3 +196,8 @@ const UnexpectedLookupMapError = new AstroError({
...AstroErrorData.UnknownContentCollectionError,
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}`];
+}