We’ve installed and configured Netlify CMS, but how do we add posts to our blog? That’s where the Netlify CMS application comes in. When we installed the Netlify CMS Gatsby plugin, it configured a route in the Gatsby site, /admin, which will load the CMS user interface so that we can manage content.
Registering and logging in
On the left side of the screen is the list of collections. So far, we only have one collection, the Blog collection. The name that is displayed here is determined by the value of the label property in the collection configuration. As more collections are added, they will appear in this list.
Once we have created some blog posts, they will be listed in the center region. Currently it says “No Entries” because no posts have been created yet.
In the top right part of the screen is the “Quick add” button. This allows you to start the content creation process from any screen in the application.
Lastly, in the top left are two buttons: “Contents” and “Media.” This is used to switch between the main view and the media asset manager, which we will look at soon.
Creating a new blog post
There are three fields shown in this editor: Title, Publish Date, and Body. These correspond to the three fields we configured in the CMS configuration file for the blog collection.
- 1.
Toggles bold.
- 2.
Toggles italic.
- 3.
Toggles code/monospaced font.
- 4.
Inserts a hyperlink.
- 5.
Sets the heading style. There are six available heading levels.
- 6.
Inserts a block quote.
- 7.
Inserts an unordered list.
- 8.
Inserts an ordered list.
- 9.
Adds content to the text. Currently, the available options are images and code blocks.
- 10.
Toggles between the formatted text and the Markdown source.
Publishing the post
After a brief delay, the top of the screen will change to indicate that the new post was saved and published. The “Publish” button in the top right has changed to say “Published.”
How publishing works
A Markdown document was created for the blog post, containing the metadata in the front matter and the content in the body.
Using the GitHub API via the Git Gateway, a new commit was created containing this document on the master branch.
Since a new commit was created on the master branch, Netlify built and published a new version of the site containing the new blog post.
You will see one new commit downloaded from GitHub. If you check the src directory, you’ll see a new directory called blog. Inside that directory is a new file. The filename should look something like 2020-06-21-welcome-to-the-coffee-blog.md. This filename is generated from the configuration file. Recall that for the blog collection, we set the slug pattern to {{year}}-{{month}}-{{day}}-{{slug}}.
The Markdown file that was generated by the CMS
Adding media
The Netlify CMS application also includes an interface for managing media files. You can upload images and other media here.
Let’s upload an image to add to our blog post. Open up your favorite image search engine and find an image of a cup of coffee, then save it to your computer.
Then, in the media manager, click the “Upload” button. Select the image that you downloaded in the file chooser that appears, and it will be added to your media library. This is done by using the Git Gateway to create a new commit in the repository containing the image – media files are also stored in the repository.
Alternative media storage options
As with the site content, all media is stored in your Git repository. After you upload an image, a new commit will be created in the repository which adds that image.
Cloudinary (https://cloudinary.com) and Uploadcare (https://uploadcare.com) are third-party CDNs for managing and distributing media content. Netlify CMS has native support for working with these services.
Netlify Large Media is another service offered by Netlify. It is a Git LFS (Large File Storage) service. Note that this service requires hosting your site on the Netlify platform.
Adding media to a blog post
Let’s add the image we just uploaded to the blog post we created previously. Click the X to close the media manager, then click the blog post in the list of content.
Inserting the image
Publishing the updated blog post
The last step to update the blog entry is to republish it. As we did before, click “Publish,” then click “Publish now.” Once the updated blog post is published, Netlify will begin deploying the new version of the site containing the updated blog post.
You will see that the blog post file was updated and a new file was added in the static/img directory. This is what we configured for the media_folder option in the CMS configuration file.
Summary
Created an account in the CMS application
Created and published a new blog post
Added an image to the blog post