Search code examples
rubymetadatablogsnanoc

How do I create 'draft' items in nanoc?


I'd like to render posts to different folders depending on a status code in the metadata.

For example, if I have an attribute of status: draft I'd like for these items to be rendered to a folder called /draft/, while status: live would be rendered to /blog/. I could then password protect the draft folder so that only I could view it. If there is no status at all it would default to draft.

Is this possible?


Solution

  • In your rules file, use the following:

    route '*' do
      if item.binary?
        item.identifier.chop + '.' + item[:extension]
      elsif item[:status]
        '/' + item[:status] + item.identifier.chop + '.' + item[:extension]
      else
        item.identifier + 'index.html'
      end
    end
    

    This will create a directory for each status you have. Eg: A source file that begins with

    ---
    title: file1
    status: testing
    ---
    

    will be created in the /testing/ folder.

    To remove leftover files after compilation, you can use “nanoc prune” (new in nanoc 3.3.x).