Gridsome Netlify CMS Guide
Prerequisites
We assume you've worked with @gridsome/source-filesystem
and @gridsome/transformer-remark
before this guide.
Gridsome requires Node.js and recommends Yarn. How to setup
Create a Gridsome project
gridsome create my-gridsome-site
to create a new projectcd my-gridsome-site
to open foldergridsome develop
to start local development server
Install the required dependencies
Gridsome already provides you a set of plugins to get you started.
yarn add netlify-cms gridsome-plugin-netlify-cms @gridsome/source-filesystem @gridsome/transformer-remark
to install the required dependenciesnpm add netlify-cms gridsome-plugin-netlify-cms @gridsome/source-filesystem @gridsome/transformer-remark
Configuration
Alright, the plugins are installed, it's now time to setup the right configuration. Open the gridsome.config.js
file and make sure it looks like this:
module.exports = {
siteName: 'Gridsome',
transformers: {
remark: {
externalLinksTarget: '_blank',
externalLinksRel: ['nofollow', 'noopener', 'noreferrer'],
anchorClassName: 'icon icon-link',
plugins: [
// ...global plugins
]
}
},
plugins: [
{
use: '@gridsome/source-filesystem',
options: {
path: 'posts/**/*.md',
typeName: 'Post',
remark: {
plugins: [
// ...local plugins
]
}
}
},
{
use: `gridsome-plugin-netlify-cms`,
options: {
publicPath: `/admin`
}
},
]
}
Please read gridsome-plugin-netlify-cms, transformer-remark for more information about the configurations.
Netlify CMS setup
It's time to add the CMS!
- Create an
admin
directory inside thesrc
- Create an
uploads
directory inside the root of your project - Add
index.html
,index.js
and aconfig.yml
file to youradmin
directory
Your index.html
should look like this:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Netlify CMS</title>
</head>
<body>
<script src="index.js" type="module"></script>
</body>
</html>
Your index.js
should look like this:
import CMS from "netlify-cms"
Your config.yml
for Github should look like this:
backend:
name: github
repo: your_name/repo_name
media_folder: "static/uploads"
public_folder: "/uploads"
collections:
- name: "posts"
label: "Posts"
folder: "posts"
create: true
slug: "{{slug}}"
fields:
- {label: "Title", name: "title", widget: "string"}
- {label: "Excerpt", name: "excerpt", widget: "string"}
- {label: "Publish Date", name: "date", widget: "date"}
- {label: "Body", name: "body", widget: "markdown"}
Your config.yml
for Bitbucket should look like this:
backend:
name: bitbucket
repo: owner-name/repo-name # Path to your Bitbucket repository
# The rest of the configuration...
Netlify CMS authentication with GitHub
Before we can start adding posts we'll have to give Netlify access to our Github, this part is crucial, please follow the steps closely. More info can be read here;
Part 1, GitHub:
- Open this link
- Click on "New OAuth App"
- Fill in all the fields according to your website and use
https://api.netlify.com/auth/done
asauthorization
callback URL
Part 2, Netlify:
- Go to your Netlify dashboard and click on your project
- Navigate to Settings > Access control > OAuth
- Under Authentication Providers, click Install Provider
- Select GitHub and enter the Client ID and Client Secret, then save (0Auth Docs - How do I find my GitHub client ID and secret?)
Netlify CMS authentication with Bitbucket
Another way of integration Netlify CMS could be with the Bitbucket OAuth. Please follow the steps closely. At the moment, there is a lack of support for Editorial Workflow when working with Bitbucket Bitbucket Editorial Workflow;
Part 1, Bitbucket:
- Open this link 1.1 Under ACCESS MANAGEMENT find OAuth link, and open it
- Scroll to "OAuth consumers" and click on the button "Add consumer"
- Fill in all the fields according to your website and use
https://api.netlify.com/auth/done
asauthorization
callback URL - Upon creation you will get the Key and Secret which will be used in Netlify
Part 2, Netlify:
- Go to your Netlify dashboard and click on your project
- Navigate to Settings > Access control > OAuth
- Under Authentication Providers, click Install Provider
- Select Bitbucket, and enter the Client ID and Client Secret from step 4 in Part 1, Bitbucket. Then click install
Start coding
Your basic blog scaffold is done, now you can query data from the GraphQL server just like you're working with the filesystem. For more info read querying data.