Collection patterns use glob syntax to match files in your repository. This guide covers advanced pattern techniques for complex content structures.
Glob Pattern Syntax
Basic Wildcards
Single Star (*) - Matches any characters except directory separator
posts/*.md
# Matches: posts/hello.md
# Matches: posts/world.md
# Does NOT match: posts/2024/hello.md
**Double Star (**)** - Matches any characters including directory separators (recursive)
posts/**/*.md
# Matches: posts/hello.md
# Matches: posts/2024/hello.md
# Matches: posts/2024/01/15/hello.md
Character Sets
Braces ({}) - Match any of the comma-separated patterns
content/{blog,docs}/**/*.md
# Matches: content/blog/post.md
# Matches: content/docs/guide.md
# Does NOT match: content/pages/about.md
Brackets ([]) - Match any character in the set
posts/202[0-4]/**/*.md
# Matches: posts/2020/post.md
# Matches: posts/2024/post.md
# Does NOT match: posts/2025/post.md
Ranges - Match character ranges
posts/[a-m]*/*.md
# Matches: posts/about/intro.md
# Matches: posts/guides/start.md
# Does NOT match: posts/news/update.md
Negation
Exclamation (!) - Exclude patterns
posts/**/!(draft-|_)*.md
# Matches: posts/published-post.md
# Does NOT match: posts/draft-post.md
# Does NOT match: posts/_hidden.md
Common Pattern Examples
Date-Based Structure
Match posts organized by date:
# Year/Month/Day structure
posts/[0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9]/*.md
# Matches: posts/2024/01/15/my-post.md
# Year/Month structure
blog/{2023,2024,2025}/*/*.md
# Matches: blog/2024/01/post.md
# Year only
content/posts/202[0-9]/**/*.md
# Matches: content/posts/2020/post.md through 2029
Category-Based Structure
Match specific categories:
# Specific categories
content/{tutorials,guides,news}/**/*.md
# All categories except one
content/!(drafts)/**/*.md
# Multiple file types
docs/**/*.{md,mdx}
Multi-Level Navigation
For documentation with sections:
# Two-level structure (category/page)
docs/*/!(_)*.md
# Matches: docs/guides/intro.md
# Does NOT match: docs/guides/subsection/page.md
# Does NOT match: docs/guides/_partial.md
# Three-level structure (section/category/page)
docs/*/*/*.md
# Matches: docs/getting-started/installation/npm.md
Special File Handling
Exclude or include specific file types:
# Exclude drafts (files starting with underscore)
posts/**/!(_)*.md
# Only published (files NOT starting with draft-)
content/**/!(draft-)*.md
# Include hidden files
content/**/.*md
# Specific filename patterns
posts/**/*-tutorial.md
Advanced Patterns
Complex Date Filtering
# Only 2024 and 2025
posts/{2024,2025}/**/*.md
# Specific months in 2024
posts/2024/{01,02,03}/**/*.md
# Q1 of any year
posts/*/{01,02,03}/**/*.md
# Last two digits of year
posts/20[2-3][0-9]/**/*.md
Language-Specific Content
# Multi-language structure
content/**/*.{en,es,fr}.md
# Matches: content/about.en.md
# Matches: content/about.es.md
# Default and localized
content/**/!(*.*.md).md
# Matches: content/about.md
# Does NOT match: content/about.en.md
Author-Based Collections
# Posts by specific authors
content/posts/{john,jane}/**/*.md
# Guest posts in separate directory
content/{posts,guest-posts}/**/*.md
# Team vs community
content/posts/{team,community}/**/*.md
Status-Based Collections
# Published only
content/published/**/*.md
# Drafts only
content/drafts/**/*.md
# Everything except archived
content/!(archived)/**/*.md
# Review queue
content/review-queue/**/*.md
Multi-Collection Strategies
Separate by Content Type
# Blog posts
Collection 1:
Path: content/blog/**/*.md
# Documentation
Collection 2:
Path: docs/**/*.mdx
# Landing pages
Collection 3:
Path: pages/**/*.md
Separate by Status
# Published posts
Collection 1:
Path: content/posts/**/!(_|draft-)*.md
# Draft posts
Collection 2:
Path: content/{drafts,posts/draft-*}/**/*.md
Separate by Date
# Current year
Collection 1:
Path: posts/2024/**/*.md
# Archive
Collection 2:
Path: posts/{2020,2021,2022,2023}/**/*.md
Separate by Category
# Tutorials
Collection 1:
Path: content/posts/tutorials/**/*.md
# Guides
Collection 2:
Path: content/posts/guides/**/*.md
# News
Collection 3:
Path: content/posts/news/**/*.md
Pattern Testing
Test Your Patterns
Before applying patterns, test them:
- Create sample file structure
- Apply pattern in collection
- Verify matched files
- Adjust pattern as needed
Common Testing Mistakes
# Wrong: Too broad
**/*.md
# Matches EVERYTHING including node_modules
# Right: Specific directory
content/**/*.md
# Matches only content directory
# Wrong: Incorrect negation
posts/!draft*.md
# Syntax error
# Right: Proper negation
posts/!(draft*)*.md
# Correctly excludes draft files
Performance Considerations
Optimize for Large Repositories
Specific paths are faster:
# Slow (scans entire repo)
**/*.md
# Fast (specific directory)
content/posts/**/*.md
Limit depth:
# Slow (unlimited depth)
posts/**/*.md
# Faster (limited depth)
posts/*/*.md
posts/*/*/*.md
Exclude large directories:
# Include node_modules (slow!)
**/*.md
# Exclude dependencies (fast)
!(node_modules|.git)/**/*.md
Pattern Best Practices
Be Specific
# Too broad
**/*.md
# Better
content/**/*.md
# Best
content/posts/**/*.md
Use Negation Wisely
# Avoid double negatives
!(!(posts))/**/*.md
# Use positive patterns
posts/**/*.md
Document Complex Patterns
Collection: Blog Posts
Path: content/{blog,articles}/**/!(draft-|_)*.{md,mdx}
Description: |
Matches blog posts and articles
Excludes files starting with "draft-" or "_"
Includes both .md and .mdx files
Test Edge Cases
Consider:
- Empty directories
- Deep nesting
- Special characters in filenames
- Different file extensions
- Hidden files
Troubleshooting Patterns
No Files Matched
Check:
- Path separators (use
/not\) - File extensions match pattern
- Directory structure matches pattern
- No typos in path
Too Many Files Matched
Solutions:
- Add more specific path segments
- Use negation to exclude directories
- Limit depth with fewer
**wildcards - Add file extension restrictions
Pattern Syntax Errors
Common errors:
# Wrong
posts/!*.md # Negation needs grouping
# Right
posts/!(draft)*.md # Negation in extglob
# Wrong
posts/**.md # Missing directory separator
# Right
posts/**/*.md # Correct recursive pattern
Real-World Examples
Next.js Blog
# Blog posts
content/posts/**/*.{md,mdx}
# Pages
src/pages/**/!(_app|_document|404).{md,mdx}
# Authors
content/authors/*.json
Documentation Site
# Getting Started
docs/getting-started/**/*.md
# Guides
docs/guides/**/*.md
# API Reference
docs/api/**/*.md
# Exclude partials
docs/**/!(\_)*.md
Multi-Language Site
# English content
content/**/*.en.md
# Spanish content
content/**/*.es.md
# All languages
content/**/*.{en,es,fr,de}.md
Monorepo Structure
# Main site blog
apps/website/content/blog/**/*.md
# Documentation
apps/docs/content/**/*.md
# Marketing pages
apps/marketing/pages/**/*.md
Next Steps
- Create Collections using these patterns
- Define Schemas for your collections
- Integrate with Your Site to consume content