Working with Globs
Certain configuration values in Forestry, such as the sidebar match
and exclude
parameters, accept what is known as a glob. A glob is a string of characters that follows a special syntax, used to match paths in a file tree.
Basic Syntax
?
matches a single character*
matches any number of characters.[abc]
matches any one character in the given set[a-z]
matches a range.{foo,bar}
matches any whole word in the given set
Globstar
Two asterisks in sequence (**
) is known as a globstar and will match 0 or more subdirectories in the path.
For example, the pattern /content/**/index.md
matches all of the following:
/content/index.md
/content/posts/index.md
/content/authors/index.md
/content/products/clothing/index.md
Practical Examples
The following are examples of some patterns you might use in your sidebar configuration’s match
or exclude
field.
Pattern | Matches |
---|---|
/data/*.json |
All JSON files in the data directory |
/data/**/*.json |
All JSON files in the data directory and any subdirectories |
**/*.{yaml,yml,json,toml} |
All JSON, YAML, or TOML files in the entire project |
{/foo.json,/data/bar.toml} |
Only /foo.json and /data/bar.toml |
Further Reading
November 13, 2018
Caught a mistake or want to contribute to the docs? Edit this page on Github!