Adding a "Draft Field" is one approach to handling "drafts" in TinaCMS
"Draft Fields" are just simply fields that can be used to indicate whether a document is a draft or not. There is nothing special about draft fields, are they are not treated any differently then any other boolean field.
The "draft" field can be added to the top level fields of a collection.
const schema = defineSchema({collections: [{name: 'post',label: 'Post',path: 'content/posts',fields: [{name: 'draft',label: 'Draft',type: 'boolean',required: true,description: 'If this is checked the post will not be published',},// ... other fields],},],})
Note: It's usually a good practice to make draft fields required. This may require adding the draft field to your existing documents
You can add a filter to filter out draft documents from your queries:
// getting production postsconst req = await client.queries.postConnection({filter: { draft: { eq: false } },})// getting all postsconst req = await client.queries.postConnection()
Read more about querying data here.
If you're using a Draft field with a static site generator like Hugo, any documents with "draft: true" will be omitted from your production site out-of-the-box.
© TinaCMS 2019–2024