Question

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?

Was it helpful?

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top