4

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?

Charles Roper
  • 20,125
  • 20
  • 71
  • 101

1 Answers1

4

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).

Denis Defreyne
  • 2,213
  • 15
  • 18
Bernard
  • 16,149
  • 12
  • 63
  • 66
  • Excellent, thanks, that pointed me in the right direction. Problem solved. Thanks @Alkaline. – Charles Roper Jan 10 '12 at 13:57
  • 1
    The extra '/' is not necessary before the identifier, as the identifier already starts with a slash. Also, in the upcoming nanoc 3.3 release, you will be able to prune leftover compiled files using “nanoc prune” and also be able to prune automatically. – Denis Defreyne Feb 07 '12 at 08:04