Coded Geekery

BlogAboutContact
BlogAboutContact

Easily Adding Drafts in Gatsby

Roger Stringer / November 05, 2019

1 min read––– views

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.

Tagged In:#code

Coded Geekery

© 2021 Roger Stringer. All rights reserved.

TwitterGitHubInstagram

Stuff

HomeAbout MeContact Me

Not Playing

Spotify

Buy me a coffee

Buy me a coffee