Creating Post Draft In Jekyll
Creating a post is a breeze; we simply create a new Markdown file, save it in the /_posts folder and it will immediately appear on the Blog. However, this could be a problem if you have put your blog online. Your message may contain unfinished judgements, errors and other things that your readers should not see.
That’s why we usually create a draft before clicking the Publish button. In this article, we will show you how to create a draft publication in Jekyll before it is made public. But first, we start the Jekyll server with the following command line.
File and directory
Before Version 1.0, it is difficult to work with a draft in Jekyll. There are many ways to deal with this.
Some have set published:false in the Post files to prevent them from publishing, and others have added future:false in the configuration file to prevent Jekyll from generating posts with a future date-which will always be published once the date has passed. Now Jekyll has made things easier to control.
Jekyll relies on a strict directory structure. When creating drafts, we need to create a new folder called _drafts. We put all the drafts in this folder. The name of the design file must not contain the publication date.
Jekyll ignores this file. You can write your message as usual and it will not be publicly displayed yet. Once you have finished your publication, you can add it to a correct date in the _posts folder and the file name.
Wait a minute, can’t we just create a folder? Well, the _drafts folder name is the official naming convention for your drafts. We can technically name the folder as we see fit, but that would prevent us from previewing our drafts.
In Jekyll, we can run the jekyll command with the –drafts flag to preview drafts: Jekyll server –watch –drafts update your Blog and you will see the draft appear in the Blog. The draft is displayed with its last modification date.
We showed you how to create a draft in Jekyll. It’s very simple. But we can streamline the workflow from design to publication using a plugin. We will discuss this in the next post.