Trying to get flat dir structure working...

123 views
Skip to first unread message

JustinClift

unread,
Feb 11, 2012, 12:37:45 AM2/11/12
to nanoc
Hi all,

Trying to get a flat directory structure working, but nanoc keeps on
barfing with an error that's making no sense to me. :(

RuntimeError: The path returned for the <Nanoc3::ItemRep:0x86d45b30
name=default binary=false raw_path= item.identifier=/> item
representation, “.html”, does not start with a slash. Please ensure
that all routing rules return a path that starts with a slash.

What I'm trying to do is output file names as /file.html instead of /
file/index.html.

For example, foo.haml, bar.haml, baz.haml should be routed to
foo.html, bar.html, baz.html instead of foo/index.html, bar/
index.html, baz/index.html.

To achieve this, I tried adding to the default route '*' bit:

elsif item[:extension] == 'haml'
# Write out haml files with a 'html' extension
item.identifier.chop + '.' + 'html'

As seen here:

https://github.com/aeolusproject/aeolus-website/blob/nanoc_busted1/nanocsite/Rules
(lines 45-47)

It's just barfing with the above though. Which is weird, as the exact
same rule works with other files using a non-haml extension.

Any ideas?

Regards and best wishes,

Justin Clift

Denis Defreyne

unread,
Feb 11, 2012, 3:01:45 AM2/11/12
to na...@googlegroups.com
Hi Justin,

The error that you are getting means that your #route block returns something that does not start with a slash.

In this case, I believe you are returning the string ".html" while you should be returning "/index.html", because the item content/index.haml has the identifier "/" and "/".chop + '.' + 'html' == ".html". I think you’d need a special case for the item with identifier "/", but it’s a bit icky (no other clean way around it though).

There’s one thing I don’t understand about your Rules file… if the item extension is .haml, you write an item /foo/ to /foo.html, otherwise you write an item /foo/ to /foo/index.html. Is this intentional? It seems a bit weird to use “clean URLs” (in the non-Haml case) and URLs with extensions at the same time.

Personally, I’d just use clean URLs all the time (that’s what the default nanoc Rules file does).

Cheers,

Denis

> --
> You received this message because you are subscribed to the nanoc discusssion group.
>
> To post to this group, send email to na...@googlegroups.com
> To unsubscribe from this group, send email to
> nanoc+un...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/nanoc?hl=en

Justin Clift

unread,
Feb 14, 2012, 5:08:37 AM2/14/12
to na...@googlegroups.com
On 11/02/2012, at 7:01 PM, Denis Defreyne wrote:
> Hi Justin,
>
> The error that you are getting means that your #route block returns something that does not start with a slash.
>
> In this case, I believe you are returning the string ".html" while you should be returning "/index.html", because the item content/index.haml has the identifier "/" and "/".chop + '.' + 'html' == ".html". I think you’d need a special case for the item with identifier "/", but it’s a bit icky (no other clean way around it though).

Thanks Denis, that's indeed the way we went with it. :)

https://github.com/aeolusproject/aeolus-website/blob/nanoc/nanocsite/Rules


> There’s one thing I don’t understand about your Rules file… if the item extension is .haml, you write an item /foo/ to /foo.html, otherwise you write an item /foo/ to /foo/index.html. Is this intentional? It seems a bit weird to use “clean URLs” (in the non-Haml case) and URLs with extensions at the same time.

Sorry, I've read this bit through a few times, and it's not making sense to me what you're trying to point out. :(

We have an existing code base, that we've imported from Webby.

Webby is a pretty simple system, it doesn't do any URL translation at all, except change haml files to .html extension.
(the way we've been using it anyway)

It keeps the directory structure from the content directory, and copies anything it doesn't recognise to the output directory verbatim.

That's pretty much what I'm trying to replicate.

Does that make sense?

Denis Defreyne

unread,
Feb 19, 2012, 3:11:57 PM2/19/12
to na...@googlegroups.com
On 14 Feb 2012, at 11:08, Justin Clift wrote:

>> There’s one thing I don’t understand about your Rules file… if the item extension is .haml, you write an item /foo/ to /foo.html, otherwise you write an item /foo/ to /foo/index.html. Is this intentional? It seems a bit weird to use “clean URLs” (in the non-Haml case) and URLs with extensions at the same time.
>
> Sorry, I've read this bit through a few times, and it's not making sense to me what you're trying to point out. :(

Never mind. I was confused by the special case for the item with identifier “/”, where where you have to append index.html.

Doing what Webby does should be quite straightfoward as Webby was inspired by nanoc. The default nanoc configuration mostly works, but if you do not want pretty URLs (e.g. /foo.html instead of /foo/index.html) then you need to adjust the routing rules (as you already did).

Denis


signature.asc

Justin Clift

unread,
Feb 20, 2012, 10:59:17 AM2/20/12
to na...@googlegroups.com

Yeah, it wasn't working properly deeper than the base directory though. :(

Discovered the =~ operator (I'm not a Ruby coder), and this seems to work:

if item[:filename] =~ /index.haml$/
item.identifier + 'index.html'
else
# Write out haml files with a flat dir structure


item.identifier.chop + '.' + 'html'

end

Hopefully I never have to look at the Rules file ever again. :)

Denis Defreyne

unread,
Feb 21, 2012, 3:00:52 PM2/21/12
to na...@googlegroups.com
On 20 Feb 2012, at 16:59, Justin Clift wrote:

> Yeah, it wasn't working properly deeper than the base directory though. :(
>
> Discovered the =~ operator (I'm not a Ruby coder), and this seems to work:
>
> if item[:filename] =~ /index.haml$/
> item.identifier + 'index.html'
> else
> # Write out haml files with a flat dir structure
> item.identifier.chop + '.' + 'html'
> end

Hi Justin,

I think that will fail for content/foo/index.haml as well (corresponding with an item /foo/), so I think the better way would be to have
if item.identifier == '/'
instead of


if item[:filename] =~ /index.haml$/

> Hopefully I never have to look at the Rules file ever again. :)

Once you have a setup that works and you’re happy with, in *theory* you don’t need to touch it again. I keep on tweaking mine though. :)

Cheers,

Denis

signature.asc

Justin Clift

unread,
Feb 22, 2012, 3:12:25 AM2/22/12
to na...@googlegroups.com
On 22/02/2012, at 7:00 AM, Denis Defreyne wrote:
> On 20 Feb 2012, at 16:59, Justin Clift wrote:
>
>> Yeah, it wasn't working properly deeper than the base directory though. :(
>>
>> Discovered the =~ operator (I'm not a Ruby coder), and this seems to work:
>>
>> if item[:filename] =~ /index.haml$/
>> item.identifier + 'index.html'
>> else
>> # Write out haml files with a flat dir structure
>> item.identifier.chop + '.' + 'html'
>> end
>
> Hi Justin,
>
> I think that will fail for content/foo/index.haml as well (corresponding with an item /foo/), so I think the better way would be to have
> if item.identifier == '/'
> instead of
> if item[:filename] =~ /index.haml$/

Strangely enough, the =~ above approach works for index.haml files in subdirectories, whereas the == '/' approach only matches the root directory and nothing deeper. It's actually what I went "from".

Figured this out using the simple puts approach in the Rules file:

puts 'Item filename: ' + item[:filename] + ' Item identifier: ' + item.identifier

That showed me what was _actually_ happening for each file being processed, so I went from there. "_


>> Hopefully I never have to look at the Rules file ever again. :)
>
> Once you have a setup that works and you’re happy with, in *theory* you don’t need to touch it again. I keep on tweaking mine though. :)

Heh yeah. Just added direct kramdown support to ours. (fixes the Markdown issues also reported)

Reply all
Reply to author
Forward
0 new messages