I don't use DocPad anymore, but this post may still be interesting to those that do. Just keep in mind that the blog you're reading now isn't generated by DocPad and may not match what this post discusses.

Here is a quick tip. I use DocPad to generate my blog, and one of the things I was used to with OctoPress was the ability to have a number of draft blog posts in progress that would appear in development mode, but would not appear when I generated the production site.

DocPad does recognize draft, published, skip, ignore, and ignored as metadata properties in a document, but those properties cause the document to be completely ignored. Even in development mode, a draft: true document will be invisible. That wasn't what I wanted, so I took a different approach.

In my blog, any document in the drafts/ subfolder is not included in any site index files when the site is generated with docpad -e static generate.

I accomplish this by defining a collection named posts in my docpad.coffee. By default, the collection contains only the documents in the posts/ subfolder. But when run in development mode, the documents from drafts/ are included in the collection and I sort them to the top so that they are always visible on the main blog index.

    posts: ->
        @getCollection('documents').findAllLive({relativeDirPath: 'posts'}, [date: -1])

            posts: ->
                @getCollection('documents').findAllLive({relativeDirPath: {'$in' : ['posts', 'drafts']}}, [relativeDirPath: 1,  date: -1])

Now that there is a collection named posts, I use it in all of the places in the blog that loop over blog posts, and so each of those places automatically includes draft posts during development mode and leaves them out otherwise. This includes all these places:

  • The main blog index
  • The archives page
  • Tag index pages
  • The atom feed

There is an important second step, though. Even though the draft posts are not includes in any indexes, they are still being generated by docpad and so can be directly accessed if someone knows the URL. I address this by doing two things. First, I have the drafts folder in my .gitignore file, so that my draft documents only ever live on my own hard drive and don't get pushed to my github repository or to my blog's host. Keep in mind that my entire blog's working folder is in a DropBox folder, so even though my draft posts aren't ever committed to git, they are available on all of my computers and are effectively backed up to the cloud as well.

In normal circumstances, the .gitignore entry is sufficient, but I also have added drafts to the ignore list of my Windows Azure deployment script as good measure just in case a draft document makes it into git somehow.