Route pages to be only 1 level below root

14 views
Skip to first unread message

Edison

unread,
Oct 18, 2009, 11:32:11 PM10/18/09
to nanoc
I'm setting up a new site using nanoc and I currently have pages in
the content folder in this form:

category/page_name.html

What I would like to do is to route all pages in subfolders so they
are only 1 level deep {ie: domain.com/page_name/}

I realised I could just put all pages in the content folders but I
like having them in category folders because it makes a lot easier to
manage.

Any help would be appreciated.

Thanks

harry...@linkslogic.com

unread,
Oct 19, 2009, 8:16:25 AM10/19/09
to nanoc
In your rules file, you'll need to make a route for those items under
the category path.

route '/category/*' do
item.identifier.sub(/^\/category\//,'') + "index.html"
end

This route would remove the category folder at the beginning of the
item's identifier and append the index.html to the end. The good thing
about doing it as a route is that it becomes part of the item and you
can call the item's path to get the corrected output location.

Nanoc is really flexible in letting you put your files wherever you
want, you just have to update the routing to tell it where.

Harry

Denis Defreyne

unread,
Oct 19, 2009, 8:30:30 AM10/19/09
to na...@googlegroups.com
On 19 Oct 2009, at 14:16, harry...@linkslogic.com wrote:

> In your rules file, you'll need to make a route for those items under
> the category path.
>
> route '/category/*' do
> item.identifier.sub(/^\/category\//,'') + "index.html"
> end
>
> This route would remove the category folder at the beginning of the
> item's identifier and append the index.html to the end. The good thing
> about doing it as a route is that it becomes part of the item and you
> can call the item's path to get the corrected output location.
>
> Nanoc is really flexible in letting you put your files wherever you
> want, you just have to update the routing to tell it where.

Hi,

That's a good answer, except that nanoc is spelled nanoc, not Nanoc. :)

A more general route could be this:

route '*' do
item.identifier =~ %r{/([^/]+)/$}
last_part = $1
"/#{last_part}/index.html"
end

I guess you get the idea. :)

Regards,

Denis

--
Denis Defreyne
denis.d...@stoneship.org

Reply all
Reply to author
Forward
0 new messages