Coded Geekery

Easily Adding Drafts in Gatsby

November 05, 2019

I wanted an easy way to add drafts in this blog that I can work on easily from different devices, push to the repo and not worry about it going to production.

I looked at a few ideas, and finally came up with setting it in the gatsby-config.js file, all I had to do was add an ignore tag to the gatsby-source-filesystem declaration so that any folders that begin with draft- will be ignored:

    {
      resolve: `gatsby-source-filesystem`,
      options: {
        path: `${__dirname}/content/blog`,
        ignore: process.env.NODE_ENV === `production` && [`**/draft-*`],
        name: `blog`,
      },
    },

That’s it, when I deploy to netlify, I have the NODE_ENV variable set to production as an environmental variable, and this means any folder starting with draft- in my content folder gets ignored and not published.

Then, when I’m ready to publish the post, I just remove draft- from the folder name, push the change to the repo, and that’s it.

I know there are several other methods that can be used, but this one worked best for me.

Posted in: #Code

Roger Stringer

Written by Roger Stringer, Coded Geekery is a blog designed to give me a forum to talk and think. You should follow me on Twitter