Static CMS
Star StaticJsCMS/static-cms on GitHub
DocsContributingCommunity

Beta Features

Static CMS runs new functionality in an open beta format from time to time. That means that this functionality is totally available for use, an it might be ready for primetime, but it could break or change without notice.

Use these features at your own risk.

Folder Collections Path

See Folder Collections Path.

Nested Collections

Seed Nested Collections.

Commit Message Templates

You can customize the templates used by Static CMS to generate commit messages by setting the commit_messages option under backend in your Static CMS config.

Template tags wrapped in curly braces will be expanded to include information about the file changed by the commit. For example, {{path}} will include the full path to the file changed.

Setting up your Static CMS config to recreate the default values would look like this:

backend:
  commit_messages:
    create: Create {{collection}} "{{slug}}"
    update: Update {{collection}} "{{slug}}"
    delete: Delete {{collection}} "{{slug}}"
    uploadMedia: Upload "{{path}}"
    deleteMedia: Delete "{{path}}"

Static CMS generates the following commit types:

Commit typeWhen is it triggered?Available template tags
createA new entry is createdslug, path, collection, author-login, author-name
updateAn existing entry is changedslug, path, collection, author-login, author-name
deleteAn existing entry is deletedslug, path, collection, author-login, author-name
uploadMediaA media file is uploadedpath, author-login, author-name
deleteMediaA media file is deletedpath, author-login, author-name

Template tags produce the following output:

  • {{slug}}: the url-safe filename of the entry changed
  • {{collection}}: the name of the collection containing the entry changed
  • {{path}}: the full path to the file changed
  • {{message}}: the relevant message based on the current change (e.g. the create message when an entry is created)
  • {{author-login}}: the login/username of the author
  • {{author-name}}: the full name of the author (might be empty based on the user's profile)

Image widget file size limit

You can set a limit to as what the maximum file size of a file is that users can upload directly into a image field.

Example config:

- label: 'Featured Image'
  name: 'thumbnail'
  widget: 'image'
  default: '/uploads/chocolate-dogecoin.jpg'
  media_library:
    config:
      max_file_size: 512000 # in bytes, only for default media library

Summary string template transformations

You can apply transformations on fields in a summary string template using filter notation syntax.

Example config:

collections:
  - name: 'posts'
    label: 'Posts'
    folder: '_posts'
    summary: "{{title | upper}} - {{date | date('YYYY-MM-DD')}} - {{body | truncate(20, '***')}}"
    fields:
      - { label: 'Title', name: 'title', widget: 'string' }
      - { label: 'Publish Date', name: 'date', widget: 'datetime' }
      - { label: 'Body', name: 'body', widget: 'markdown' }

The above config will transform the title field to uppercase and format the date field using YYYY-MM-DD format. Available transformations are upper, lower, date('<format>'), default('defaultValue'), ternary('valueForTrue','valueForFalse') and truncate(<number>)/truncate(<number>, '<string>')

Registering to CMS Events

You can execute a function when a specific CMS event occurs.

Example usage:

CMS.registerEventListener({
  name: 'prePublish',
  handler: ({ author, entry }) => console.info(JSON.stringify({ author, data: entry.data })),
});

Supported events are prePublish, postPublish, preSave and postSave. The preSave hook can be used to modify the entry data like so:

CMS.registerEventListener({
  name: 'preSave',
  handler: ({ entry }) => {
    return entry.data.set('title', 'new title');
  },
});