Drafts in Jekyll are useful if you like to write posts in advance.
To create a draft in Jekyll, create a folder in the root called _drafts. You will keep your draft posts here.
The difference between the posts in this folder and in the regular _posts folder is
-
The posts in the
_draftsfolder won't be published until you move the posts to the_postsfolder. However, you can view the posts in the_draftsfolder using the--draftsflag. -
The posts in the
_draftsfolder typically don't have the date in the file name. i.e instead of2020-01-01-post-1.md, it would bepost-1.md. You add the date after you move it to the_postsfolder. I will show you how to work around this as well using the--futureflag.
Viewing the posts in the _drafts folder
To view the posts in the _drafts folder, run the bundle exec jekyll serve --drafts command (or jekyll serve --drafts depending on which one works for you). This will allow you to view the drafts.
If you want to keep the dates in the filename of the drafts, then run bundle exec jekyll serve --drafts --future. More info on viewing Jekyll posts with a future date in this article. I actually do it this way because I like to have the filename with the dates so that I know when I want to publish the post.
My typical workflow is
-
Create the post in the
_draftsfolder. -
Once I want to publish the post, I move the post in the
_postsfolder (if you don't have the date in the filename, remember to add it).