Collections represent a type of content (EX, blog post, page, author, etc). We recommend using singular naming in a collection (Ex: use post and not posts).
Note: Must provide only one offields
ortemplates
but never both
The name of the collection that is used in the GraphQL schema. A name can only be used once and an error will occur if two or more collections have the same name. This name cannot have spaces, dashes, or special characters. It must be a valid GraphQL name. We recommend using singular naming in a collection (Ex: use post and not posts).
The path to a folder where the content is stored. By default, the path is relative to where the CLI is running but this can be changed by using the --rootPath
CLI flag. Paths do not have to be unique across collections as long as a different format
or match
is specified. The CLI will print a warning if there are overlapping documents.
The file extension of all the documents in this collection. (Default extension is "md"). Must be one of "md"
, "markdown"
, "mdx"
,"json"
, "toml"
, or "yaml"
.
The format is used to determine the parser that will be used to parse the document. The format is also used to determine the extension of the file when a new document is created. We do not support more then one format per collection but you can work around this by doing the following:
// Fields for all postsconst fields = [// an array of fields]export const defineConfig({schema: {collections: [{name: 'posts',label: 'Blog Posts',path: 'content/posts',format: 'mdx',fields,},{name: 'posts-json',label: 'Blog Posts',path: 'content/posts',format: 'json',fields,},],},})
A glob pattern that will be used to match a subset of the files in the path
directory.
The provided pattern does not have to include the file extension. The extension will be added automatically based on the format
of the collection. The final pattern that is used will be determined by match
, format
and path
.
<path>/<match.include>.<format>
For example, if you have a collection with the following:
{path: 'content/posts',match: {include: '*',},format: 'md'}
The final pattern used would be
content/posts/*.md
?
matches a single character*
matches any number of any characters (except /
)[abc]
matches any one character in the given set[a-z]
matches a range.{foo,bar}
matches any whole word in the given set*
Example:
{path: 'content/posts',match: {include: '*',},format: 'md'}
Matches all files in content/posts
folder but does not match subdirectories. It would match content/posts/hello-world.md
but not content/posts/subfolder/foo.md
Example:
{path: 'content/config',match: {include: 'index',},format: 'json'}
This matches a single file content/config/index.json
. It will not match on anything else.
Example:
{path: 'content/config',match: {include: '{foo,bar}',},format: 'json'}
This matches on content/config/foo.json
and content/config/bar.json
. It will not match on anything else.
Example:
{path: 'content/config',match: {include:'foo-{bar,baz}',},format: 'json'}
This will match on content/config/foo-bar.json
and content/config/foo-baz.json
. It will not match on anything else.
This works the same as match.include
but will exclude any files that match the pattern. This is useful for excluding files that you don't want to be editable or that are a part of a different collection.
The resulting pattern is the same except that it is prefixed with !
!(<path>/<match.exclude>.<format>)
{path: 'content/posts',match: {exclude: '**/index',},format: 'md'}
This will exclude all index.md
files from your collection.
The default item that will be used when a new document is created. This is useful for setting default values for fields. The default item can be a function that takes in the collection
and returns the default item. This is useful for setting default values that are based on the collection.
Note: This will not update existing documents. It will only be used when a new document is created.
export default defineConfig({//...schema: {collections: [{name: 'posts',label: 'Blog Posts',path: 'content/posts',format: 'mdx',defaultItem: () => {return {title: 'New Post',date: new Date().toISOString(),}},fields: [{name: 'title',type: 'string',},{name: 'date',type: 'datetime',},],},],},})
Now when a new document is created the name and date fields will have default values.
export default defineConfig({//...schema: {collections: [{name: 'posts',label: 'Blog Posts',path: 'content/posts',format: 'mdx',fields: [// An array of fields],},],},})
export default defineConfig({//...schema: {collections: [{name: 'posts',label: 'Blog Posts',path: 'content/posts',format: 'mdx',ui: {router: ({ document }) => {// navigate to the post that was clickedreturn `/post/${document._sys.filename}`},},fields: [// An array of fields],},{label: 'Global',name: 'global',path: 'content/global',ui: {global: true,},format: 'json',fields: [// An array of fields],},],},})
export default defineConfig({//...schema: {collections: [{name: 'posts',label: 'Blog Posts',path: 'content/posts',format: 'mdx',defaultItem: () => {return {// Return a default title and the current date as the default datetitle: 'new post',date: new Date().toISOString(),}},fields: [{label: 'Title',name: 'title',type: 'string',},{label: 'Date',name: 'date',type: 'datetime',},],},],},})
For more information check out the content modeling docs
export default defineConfig({//...schema: {collections: [{label: 'Navigation',name: 'navigation',path: 'content/navigation',ui: {// Don't allow editors to create new navigation itemsallowedActions: {create: false,delete: false,createNestedFolder: false,},},format: 'json',fields: [// An array of fields],},],},})
Last Edited: October 29, 2024
© TinaCMS 2019–2024