Jekyll Draft Publishing Plugin

I’ve migrated this blog (again, I know) and have finally settled on Jekyll and Markdown as my publishing platform. The only thing I didn’t like about it was the lack of a quick publishing workflow for my drafts, so I wrote a small plugin to handle the process.

First off, I added a _drafts and a _publish folder to the root of my Jekyll install:

|-- _config.yml
|-- _drafts
|   `--
|-- _includes
|-- _layouts
|   |-- default.html
|   `-- post.html
|-- _posts
|   |--
|   `--
|-- _publish
|-- _site
`-- index.html

Next, I added the following publisher.rb plugin to the _plugins folder:

module Jekyll
  class PostPublisher < Generator
    safe false
    def replace(filepath, regexp, *args, &block)
      content =, *args, &block), 'wb') { |file| file.write(content) }
    def generate(site)
      @files = Dir["_publish/*"]
      @files.each_with_index { |f,i| 
        now ="%Y-%m-%d %H:%M:%S")
        replace(f, /^date: unpublished/mi) { |match| "date: \"" + now + "\"" }
        now ="%Y-%m-%d")
        File.rename(f, "_posts/#{now}-#{File.basename(f)}") 

Gist Source:

With this in place, I can leave the date off my draft file name, for example:


and when I finish writing the post, I just move it to the _publish folder.


The Jekyll plugin takes care of adding the Y-m-d to the beginning of the file and moves in into the _posts folder.


Also, for more accurate date sorting my default YAML template includes a date: unpublished tag:

title: ""
date: unpublished
layout: post

Post content

The publisher.rb plugin automatically replaces date: unpublished with a timestamp when the post is published:

title: ""
date: "2013-02-01 09:29:16"
layout: post

Post content

This simplifies a few steps in the workflow, removing the manual date entry and I can use dropbox and iOS apps to manage the _drafts and _publish folders while Jekyll can run on a different machine to update the site.

Next I’ll update the plugin to allow scheduling posts for the future.