Supplying the initial contents for new files

Last modified: March 13th, 2023

Working with a specific static site generator?
Customize CloudCannon's documentation to suit your SSG.

Great! We'll show you documentation relevant to .
You can change this any time using the dropdown in the navigation bar.

When you create a file for a collection in CloudCannon, the initial contents and file extension are copied from a schema file configured for the collection.

Follow these steps to create and configure a schema for your collection.

Here's an example schema file and the required configuration for a posts collection:

schemas/post.md
copied
---
title:
author:
image:
---
cloudcannon.config.yaml
copied
collections_config:
  posts:
    schemas:
      default:
        path: schemas/post.md
cloudcannon.config.json
copied
{
  "collections_config": {
    "posts": {
      "schemas": {
        "default": {
          "path": "schemas/post.md"
        }
      }
    }
  }
}
cloudcannon.config.js
copied
module.exports = {
  collections_config: {
    posts: {
      schemas: {
        default: {
          path: "schemas/post.md"
        }
      }
    }
  }
};

Without a schema, the contents of another content file in the collection is used instead. The extension is copied as-is, and the contents are copied with some inputs cleared.

Creating a file from a schema adds a _schema field to the front matter or data to keep track of what schema the file was created from. Schemas also keep data consistent by updating the available inputs when editing existing files so it's important that this is set correctly.

The default schema is used if this field does not exist. You can change the field from _schema with the schema_key option when defining your collections.

content/posts/my-new-post.md
copied
---
_schema: default
title: My new post
author: /authors/jane
image: /images/posts/header.png
---
This is the content of my new post!

Schemas are also used to manage and keep data consistent across files in a collection, as well as providing the default add_options for creating new files.

Related Articles

Open in a new tab