Netlify CMS
Overview
Netlify CMS is an open source content management system for your Git workflow that enables you to provide editors with a friendly UI and intuitive workflows. You can use it with any static site generator to create faster, more flexible web projects. Content is stored in your Git repository alongside your code for easier versioning, multi-channel publishing, and the option to handle content updates directly in Git.
At its core, Netlify CMS is an open-source React app that acts as a wrapper for the Git workflow, using the GitHub, GitLab, or Bitbucket API. This provides many advantages, including:
Fast, web-based UI: With rich-text editing, real-time preview, and drag-and-drop media uploads.
Platform agnostic: Works with most static site generators.
Easy installation: Add two files to your site and hook up the backend by including those files in your build process or linking to our Content Delivery Network (CDN).
Modern authentication: Using GitHub, GitLab, or Bitbucket and JSON web tokens.
Flexible content types: Specify an unlimited number of content types with custom fields.
Fully extensible: Create custom-styled previews, UI widgets, and editor plugins.
Netlify CMS vs. Netlify
Netlify.com is a platform you can use to automatically build, deploy, serve, and manage your frontend sites and web apps. It also provides a variety of other features like form processing, serverless functions, and split testing. Not all Netlify sites use Netlify CMS, and not all sites using Netlify CMS are on Netlify.
The folks at Netlify created Netlify CMS to fill a gap in the static site generation pipeline. There were some great proprietary headless CMS options, but no real contenders that were open source and extensible—that could turn into a community-built ecosystem like WordPress or Drupal. For that reason, Netlify CMS is made to be community-driven, and has never been locked to the Netlify platform (despite the name).
With this in mind, you can:
Use Netlify CMS without Netlify and deploy your site where you always have, hooking up your own CI, site hosting, CDN, etc.
Use Netlify without Netlify CMS and edit your static site in your code editor.
Or, use them together and have a fully-working CMS-enabled site with one click!
If you hook up Netlify CMS to your website, you're basically adding a tool for content editors to make commits to your site repository without touching code or learning Git.
Find out more
Get a feel for the UI in the demo site. (No login required. Click the login button to go straight to the CMS editor UI.)
Start with a template to make a Netlify CMS-enabled site of your own.
Configure your existing site by following a tutorial or checking configuration options.
Ask questions and share ideas in the Netlify CMS community chat.
Get involved in new developments and become a contributor.
Beta Features!
We run new functionality in an open beta format from time to time. That means that this functionality is totally available for use, and we think it might be ready for primetime, but it could break or change without notice.
Use these features at your own risk.
Working with a Local Git Repository
**added in **netlify-cms@2.10.17** / **netlify-cms-app@2.11.14
You can connect Netlify CMS to a local Git repository, instead of working with a live repo.
Navigate to a local Git repository configured with the CMS.
Add the top-level property
local_backend
configuration to yourconfig.yml
:
Run
npx netlify-cms-proxy-server
from the root directory of the above repository.If the default port (8081) is in use, the proxy server won't start and you will see an error message. In this case, follow these steps before proceeding.
Start your local development server (e.g. run
gatsby develop
).Open http://localhost:8000/admin to verify that your can administer your content locally.
Note: netlify-cms-proxy-server
runs an unauthenticated express server. As any client can send requests to the server, it should only be used for local development.
Configure the Netlify CMS proxy server port number
Create a
.env
file in the project's root folder and define the PORT you'd like the proxy server to use
Update the
local_backend
object inconfig.yml
and specify aurl
property to use your custom port number
GitLab and BitBucket Editorial Workflow Support
**added in **netlify-cms@2.10.6** / **netlify-cms-app@2.11.3
You can enable the Editorial Workflow with the following line in your Netlify CMS config.yml
file:
In order to track unpublished entries statuses the GitLab implementation uses merge requests labels and the BitBucket implementation uses pull requests comments.
i18n Support
The CMS can provide a side by side interface for authoring content in multiple languages. Configuring the CMS for i18n support requires top level configuration, collection level configuration and field level configuration.
Top level configuration
Collection level configuration
When using a file collection, you must also enable i18n for each individual file:
Field level configuration
Example configuration:
Limitations
File collections support only
structure: single_file
.List widgets only support
i18n: true
.i18n
configuration on sub fields is ignored.Object widgets only support
i18n: true
andi18n
configuration should be done per field:
GitHub GraphQL API
Experimental support for GitHub's GraphQL API is now available for the GitHub backend.
Note: not currently compatible with Git Gateway.
For many queries, GraphQL allows data to be retrieved using less individual API requests compared to a REST API. GitHub's GraphQL API still does not support all mutations necessary to completely replace their REST API, so this feature only calls the new GraphQL API where possible.
You can use the GraphQL API for the GitHub backend by setting backend.use_graphql
to true
in your CMS config:
Learn more about the benefits of GraphQL in the GraphQL docs.
Open Authoring
When using the GitHub backend, you can use Netlify CMS to accept contributions from GitHub users without giving them access to your repository. When they make changes in the CMS, the CMS forks your repository for them behind the scenes, and all the changes are made to the fork. When the contributor is ready to submit their changes, they can set their draft as ready for review in the CMS. This triggers a pull request to your repository, which you can merge using the GitHub UI.
At the same time, any contributors who do have write access to the repository can continue to use Netlify CMS normally.
More details and setup instructions can be found on the Open Authoring docs page.
Folder Collections Path
By default the CMS stores folder collection content under the folder specified in the collection setting.
For example configuring folder: posts
for a collection will save the content under posts/post-title.md
.
You can now specify an additional path
template (similar to the slug
template) to control the content destination.
This allows saving content in subfolders, e.g. configuring path: '{{year}}/{{slug}}'
will save the content under posts/2019/post-title.md
.
Folder Collections Media and Public Folder
By default the CMS stores media files for all collections under a global media_folder
directory as specified in the configuration.
When using the global media_folder
directory any entry field that points to a media file will use the absolute path to the published file as designated by the public_folder
configuration.
For example configuring:
And saving an entry with an image named image.png
will result in the image being saved under static/media/image.png
and relevant entry fields populated with the value of /media/image.png
.
Some static site generators (e.g. Gatsby) work best when using relative image paths.
This can now be achieved using a per collection media_folder
configuration which specifies a relative media folder for the collection.
For example, the following configuration will result in media files being saved in the same directory as the entry, and the image field being populated with the relative path to the image.
More specifically, saving an entry with a title of example post
with an image named image.png
will result in a directory structure of:
And for the image field being populated with a value of image.png
.
Note: When specifying a path
on a folder collection, media_folder
defaults to an empty string.
Available template tags:
Supports all of the slug
templates and:
{{dirname}}
The path to the file's parent directory, relative to the collection'sfolder
.{{filename}}
The file name without the extension part.{{extension}}
The file extension.{{media_folder}}
The globalmedia_folder
.{{public_folder}}
The globalpublic_folder
.
List Widget: Variable Types
Before this feature, the list widget allowed a set of fields to be repeated, but every list item had the same set of fields available. With variable types, multiple named sets of fields can be defined, which opens the door to highly flexible content authoring (even page building) in Netlify CMS.
Note: this feature does not yet support default previews and requires registering a preview template in order to show up in the preview pane.
To use variable types in the list widget, update your field configuration as follows:
Instead of defining your list fields under
fields
orfield
, define them undertypes
. Similar tofields
,types
must be an array of field definition objects.Each field definition under
types
must use theobject
widget (this is the default value forwidget
).
Additional list widget options
types
: a nested list of object widgets. All widgets must be of typeobject
. Every object widget may define different set of fields.typeKey
: the name of the field that will be added to every item in list representing the name of the object widget that item belongs to. Ignored iftypes
is not defined. Default istype
.summary
: allows customization of a collapsed list item object in a similar way to a collection summary
Example Configuration
The example configuration below imagines a scenario where the editor can add two "types" of content, either a "carousel" or a "spotlight". Each type has a unique name and set of fields.
Example Output
The output for the list widget will be an array of objects, and each object will have a type
key with the name of the type used for the list item. The type
key name can be customized via the typeKey
property in the list configuration.
If the above example configuration were used to create a carousel, a spotlight, and another carousel, the output could look like this:
Custom Mount Element
Netlify CMS always creates its own DOM element for mounting the application, which means it always takes over the entire page, and is generally inflexible if you're trying to do something creative, like injecting it into a shared context.
You can now provide your own element for Netlify CMS to mount in by setting the target element's ID as nc-root
. If Netlify CMS finds an element with this ID during initialization, it will mount within that element instead of creating its own.
Manual Initialization
Netlify CMS can now be manually initialized, rather than automatically loading up the moment you import it. The whole point of this at the moment is to inject configuration into Netlify CMS before it loads, bypassing need for an actual Netlify CMS config.yml
. This is important, for example, when creating tight integrations with static site generators.
Assuming you have the netlify-cms package installed to your project, manual initialization works by setting window.CMS_MANUAL_INIT = true
before importing the CMS:
Raw CSS in registerPreviewStyle
registerPreviewStyle
registerPreviewStyle
can now accept a CSS string, in addition to accepting a url. The feature is activated by passing in an object as the second argument, with raw
set to a truthy value. This is critical for integrating with modern build tooling. Here's an example using webpack:
Squash merge GitHub pull requests
When using the Editorial Workflow with the github
or GitHub-connected git-gateway
backends, Netlify CMS creates a pull request for each unpublished entry. Every time the unpublished entry is changed and saved, a new commit is added to the pull request. When the entry is published, the pull request is merged, and all of those commits are added to your project commit history in a merge commit.
The squash merge option causes all commits to be "squashed" into a single commit when the pull request is merged, and the resulting commit is rebased onto the target branch, avoiding the merge commit altogether.
To enable this feature, you can set the following option in your Netlify CMS config.yml
:
Commit Message Templates
You can customize the templates used by Netlify CMS to generate commit messages by setting the commit_messages
option under backend
in your Netlify CMS config.yml
.
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 Netlify CMS config.yml
to recreate the default values would look like this:
Netlify CMS generates the following commit types:
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. thecreate
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:
Summary string template transformations
You can apply transformations on fields in a summary string template using filter notation syntax.
Example config:
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
and date('<format>')
Registering to CMS Events
You can execute a function when a specific CMS event occurs.
Example usage:
Supported events are prePublish
, postPublish
, preUnpublish
, postUnpublish
, preSave
and postSave
. The preSave
hook can be used to modify the entry data like so:
Dynamic Default Values
When linking to /admin/#/collections/posts/new
you can pass URL parameters to pre-populate an entry.
For example given the configuration:
clicking the following link: /#/collections/posts/new?title=first&object.title=second&body=%23%20content
will open the editor for a new post with the title
field populated with first
, the nested object.title
field with second
and the markdown body
field with # content
.
Note: URL Encoding might be required for certain values (e.g. in the previous example the value for body
is URL encoded).
Nested Collections
Allows a folder collection to show a nested structure of entries and edit the locations of the entries.
Example configuration:
Nested collections expect the following directory structure:
Remark plugins
You can register plugins to customize remark
, the library used by the richtext editor for serializing and deserializing markdown.
Note that netlify-widget-markdown
currently uses remark@10
, so you should check a plugin's compatibility first.
Add to Your Site
You can adapt Netlify CMS to a wide variety of projects. It works with any content written in markdown, JSON, YAML, or TOML files, stored in a repo on GitHub, GitLab, or Bitbucket. You can also create your own custom backend.
This tutorial guides you through the steps for adding Netlify CMS to a site that's built with a common static site generator, like Jekyll, Hugo, Hexo, or Gatsby. Alternatively, you can start from a template or dive right into configuration options.
App File Structure
A static admin
folder contains all Netlify CMS files, stored at the root of your published site. Where you store this folder in the source files depends on your static site generator. Here's the static file location for a few of the most popular static site generators:
If your generator isn't listed here, you can check its documentation, or as a shortcut, look in your project for a css
or images
folder. The contents of folders like that are usually processed as static files, so it's likely you can store your admin
folder next to those. (When you've found the location, feel free to add it to these docs by filing a pull request!)
Inside the admin
folder, you'll create two files:
The first file, admin/index.html
, is the entry point for the Netlify CMS admin interface. This means that users navigate to yoursite.com/admin/
to access it. On the code side, it's a basic HTML starter page that loads the Netlify CMS JavaScript file. The second file, admin/config.yml
, is the heart of your Netlify CMS installation, and a bit more complex. The Configuration section covers the details.
In this example, we pull the admin/index.html
file from a public CDN.
In the code above the script
is loaded from the unpkg
CDN. Should there be any issue, jsDelivr
can be used as an alternative source. Simply set the src
to https://cdn.jsdelivr.net/npm/netlify-cms@^2.0.0/dist/netlify-cms.js
Installing with npm
You can also use Netlify CMS as an npm module. Wherever you import Netlify CMS, it automatically runs, taking over the current page. Make sure the script that imports it only runs on your CMS page. First install the package and save it to your project:
Then import it (assuming your project has tooling for imports):
Configuration
Configuration is different for every site, so we'll break it down into parts. Add all the code snippets in this section to your admin/config.yml
file.
Backend
We're using Netlify for our hosting and authentication in this tutorial, so backend configuration is fairly straightforward.
For GitHub and GitLab repositories, you can start your Netlify CMS config.yml
file with these lines:
(For Bitbucket repositories, use the Bitbucket backend instructions instead.)
The configuration above specifies your backend protocol and your publication branch. Git Gateway is an open source API that acts as a proxy between authenticated users of your site and your site repo. (We'll get to the details of that in the Authentication section below.) If you leave out the branch
declaration, it defaults to master
.
Editorial Workflow
Note: Editorial workflow works with GitHub repositories, and support for GitLab and Bitbucket is in beta.
By default, saving a post in the CMS interface pushes a commit directly to the publication branch specified in backend
. However, you also have the option to enable the Editorial Workflow, which adds an interface for drafting, reviewing, and approving posts. To do this, add the following line to your Netlify CMS config.yml
:
Media and Public Folders
Netlify CMS allows users to upload images directly within the editor. For this to work, the CMS needs to know where to save them. If you already have an images
folder in your project, you could use its path, possibly creating an uploads
sub-folder, for example:
If you're creating a new folder for uploaded media, you'll need to know where your static site generator expects static files. You can refer to the paths outlined above in App File Structure, and put your media folder in the same location where you put the admin
folder.
Note that themedia_folder
file path is relative to the project root, so the example above would work for Jekyll, GitBook, or any other generator that stores static files at the project root. However, it would not work for Hugo, Hexo, Middleman or others that store static files in a subfolder. Here's an example that could work for a Hugo site:
The configuration above adds a new setting, public_folder
. While media_folder
specifies where uploaded files are saved in the repo, public_folder
indicates where they are found in the published site. Image src
attributes use this path, which is relative to the file where it's called. For this reason, we usually start the path at the site root, using the opening /
.
If public_folder
is not set, Netlify CMS defaults to the same value as media_folder
, adding an opening /
if one is not included.
Collections
Collections define the structure for the different content types on your static site. Since every site is different, the collections
settings differ greatly from one site to the next.
Let's say your site has a blog, with the posts stored in _posts/blog
, and files saved in a date-title format, like 1999-12-31-lets-party.md
. Each post begins with settings in yaml-formatted front matter, like so:
Given this example, our collections
settings would look like this in your NetlifyCMS config.yml
file:
Let's break that down:
As described above, the widget
property specifies a built-in or custom UI widget for a given field. When a content editor enters a value into a widget, that value is saved in the document front matter as the value for the name
specified for that field. A full listing of available widgets can be found in the Widgets doc.
Based on this example, you can go through the post types in your site and add the appropriate settings to your Netlify CMS config.yml
file. Each post type should be listed as a separate node under the collections
field. See the Collections reference doc for more configuration options.
Filter
The entries for any collection can be filtered based on the value of a single field. The example collection below only shows post entries with the value en
in the language
field.
Authentication
Now that you have your Netlify CMS files in place and configured, all that's left is to enable authentication. We're using the Netlify platform here because it's one of the quickest ways to get started, but you can learn about other authentication options in the Backends doc.
Setup on Netlify
Netlify offers a built-in authentication service called Identity. In order to use it, connect your site repo with Netlify. Netlify has published a general Step-by-Step Guide for this, along with detailed guides for many popular static site generators, including Jekyll, Hugo, Hexo, Middleman, Gatsby, and more.
Enable Identity and Git Gateway
Netlify's Identity and Git Gateway services allow you to manage CMS admin users for your site without requiring them to have an account with your Git host or commit access on your repo. From your site dashboard on Netlify:
Go to Settings > Identity, and select Enable Identity service.
Under Registration preferences, select Open or Invite only. In most cases, you want only invited users to access your CMS, but if you're just experimenting, you can leave it open for convenience.
If you'd like to allow one-click login with services like Google and GitHub, check the boxes next to the services you'd like to use, under External providers.
Scroll down to Services > Git Gateway, and click Enable Git Gateway. This authenticates with your Git host and generates an API access token. In this case, we're leaving the Roles field blank, which means any logged in user may access the CMS. For information on changing this, check the Netlify Identity documentation.
Add the Netlify Identity Widget
With the backend set to handle authentication, now you need a frontend interface to connect to it. The open source Netlify Identity Widget is a drop-in widget made for just this purpose. To include the widget in your site, add the following script tag in two places:
Add this to the <head>
of your CMS index page at /admin/index.html
, as well as the <head>
of your site's main index page. Depending on how your site generator is set up, this may mean you need to add it to the default template, or to a "partial" or "include" template. If you can find where the site stylesheet is linked, that's probably the right place. Alternatively, you can include the script in your site using Netlify's Script Injection feature.
When a user logs in with the Netlify Identity widget, an access token directs to the site homepage. In order to complete the login and get back to the CMS, redirect the user back to the /admin/
path. To do this, add the following script before the closing body
tag of your site's main index page:
Note: This example script requires modern JavaScript and does not work on IE11. For legacy browser support, use function expressions (function () {}
) in place of the arrow functions (() => {}
), or use a transpiler such as Babel.
Accessing the CMS
Your site CMS is now fully configured and ready for login!
If you set your registration preference to "Invite only," invite yourself (and anyone else you choose) as a site user. To do this, select the Identity tab from your site dashboard, and then select the Invite users button. Invited users receive an email invitation with a confirmation link. Clicking the link will take you to your site with a login prompt.
If you left your site registration open, or for return visits after confirming an email invitation, access your site's CMS at yoursite.com/admin/
.
Note: No matter where you access Netlify CMS — whether running locally, in a staging environment, or in your published site — it always fetches and commits files in your hosted repository (for example, on GitHub), on the branch you configured in your Netlify CMS config.yml file. This means that content fetched in the admin UI matches the content in the repository, which may be different from your locally running site. It also means that content saved using the admin UI saves directly to the hosted repository, even if you're running the UI locally or in staging.
Last updated