I'm still having a lot of trouble getting tags to working properly within Nanoc 2.1. There has been a lot of really great work done on this since earlier versions. However, it's still not quite at the point of working "out of the box".. yet.
I'm working towards having tag index pages automatically generated. At the moment, I'm trying to do this via a Rake task and prodding around with the Nanoc API. Seems simple enough but I am missing something!
I took the basic skeleton for trawling tags out of my site via this article here:
And applied some modification to then inline compile the pages rather than generating an intermediate tag page in content. That bit, I think works fine. I also hacked it slightly to add a different layout attribute for tags index pages and dumped this into a Rake task:
# Build pages for each tag tags_without_pages.each do |t| # Buid page puts t page = Nanoc::Page.new("Tag: #{t}", { :tags => t, :layout => "tag"
}, "/tags/#{t}")
page.site = site page.build_reps pages << page site.compiler.run([page]) end
But, and this is where I'm falling over, when attempting to compile the page above I run into two key problems:
1) I can manage to generate an index page of pages titles only. If I try to use any other attributes of the page, I get Nil problems all over the place.
E.g. my regular front page "render-a-summary-of-the-last-few-articles" ERB looks like this:
I see compile errors of "can't covert Nil into String" which go away if I remove references to page attributes other than "page_id" (which seems to be the only attribute I can safely reference). i.e. there is something different about the non-tags index articles somewhere...
So, what's the proper way to generate tag index pages?
2) A really annoying problem is also that my 'tags_for' links are all now broken too when using the autocompiler.
E.g. say I have an article 'foo' that lives in /output/articles/foo/index.html - I can link to this fine as '/articles/foo/' via 'link_to' and Firefox follows it fine etc. all works as it should.
But, if I try to do the same with my tags index pages, it doesn't work, despite the <a href..> targets being identical:
<p class="excerpt"><a href="http://nanoc.stoneship.org/">Nanoc</a> in itself is great for generating templatised static HTML pages. It's very powerful and flexible with good built-in filter support and easy user... <a href="/articles/nanoc-rake/">read Expanding the Power of Nanoc with Rake</a></p>
> 1) I can manage to generate an index page of pages titles only. If I > try > to use any other attributes of the page, I get Nil problems all over > the > place.
The issue here is that the @pages array when compiling a page with ERB is actually an array of page *proxies* (Nanoc::PageProxy). @page is a proxy as well, and so are @assets and @asset (Nanoc::AssetProxy). These proxies basically "rewrite" calls like "pageproxy.foo" to "page.attribute_named(:foo)".
So, when you're getting a list of pages or assets straight from a Nanoc::Site instance, you should know that these are actual Nanoc::Pages or Nanoc::Assets, and in order to get attributes off them, you need to use attribute_named(:something).
I would love nothing more than to simply get rid of proxies entirely. In retrospect, this was a bad design decision. Unfortunately, it's hard to revert this one; if I suddenly start passing Pages (with an appropriate method_missing) instead of PageProxies around, then I risk getting backward compatibility issues.
This doesn't meant that it's impossible; it simply would require a lot of thought to make sure everything still works (fortunately nanoc has an extensive test case). It's definitely on my todo list! Possibly for 2.2...
> 2) A really annoying problem is also that my 'tags_for' links are all > now broken too when using the autocompiler. [..] But, in the second > line:
> <a href="/tags/nanoc/">nanoc</a>
> Gives a 404 when clicked on. If I instead type explicitly: > .../tags/nanoc/index.html it works fine and the page loads.
> Is this a bug in the autocompiler? In Firefox?!?
A bug in the autocompiler. When requesting a path for which no page exists (e.g. /tags/nanoc/), but which *does* contain an index filename (e.g. index.html), then the autocompiler should serve the index.html file.
This bug will be fixed soon. Thanks for letting me know! :)
Denis Defreyne wrote: > On 22 Sep 2008, at 17:24, Rob Emerson wrote:
>> 1) I can manage to generate an index page of pages titles only. If I >> try >> to use any other attributes of the page, I get Nil problems all over >> the >> place.
> The issue here is that the @pages array when compiling a page with ERB > is actually an array of page *proxies* (Nanoc::PageProxy). @page is a > proxy as well, and so are @assets and @asset (Nanoc::AssetProxy). > These proxies basically "rewrite" calls like "pageproxy.foo" to > "page.attribute_named(:foo)".
> So, when you're getting a list of pages or assets straight from a > Nanoc::Site instance, you should know that these are actual > Nanoc::Pages or Nanoc::Assets, and in order to get attributes off > them, you need to use attribute_named(:something).
> I would love nothing more than to simply get rid of proxies entirely. > In retrospect, this was a bad design decision. Unfortunately, it's > hard to revert this one; if I suddenly start passing Pages (with an > appropriate method_missing) instead of PageProxies around, then I risk > getting backward compatibility issues.
> This doesn't meant that it's impossible; it simply would require a lot > of thought to make sure everything still works (fortunately nanoc has > an extensive test case). It's definitely on my todo list! Possibly for > 2.2...
>> 2) A really annoying problem is also that my 'tags_for' links are all >> now broken too when using the autocompiler. [..] But, in the second >> line:
>> <a href="/tags/nanoc/">nanoc</a>
>> Gives a 404 when clicked on. If I instead type explicitly: >> .../tags/nanoc/index.html it works fine and the page loads.
>> Is this a bug in the autocompiler? In Firefox?!?
> A bug in the autocompiler. When requesting a path for which no page > exists (e.g. /tags/nanoc/), but which *does* contain an index filename > (e.g. index.html), then the autocompiler should serve the index.html > file.
> This bug will be fixed soon. Thanks for letting me know! :)
Thanks very much Denis - a fast and excellent reply as always!
Got it working now and it rocks.
I was just getting a bit confused between the Page and PageProxy objects
and that was catching me out.
I'll post some further notes on this in case other people are interested
or have a better approach.
Many thanks again! :)
Denis Defreyne wrote:
On 22 Sep 2008, at 17:24, Rob Emerson wrote:
1) I can manage to generate an index page of pages titles only. If I
try
to use any other attributes of the page, I get Nil problems all over
the
place.
The issue here is that the @pages array when compiling a page with ERB
is actually an array of page *proxies* (Nanoc::PageProxy). @page is a
proxy as well, and so are @assets and @asset (Nanoc::AssetProxy).
These proxies basically "rewrite" calls like "pageproxy.foo" to
"page.attribute_named(:foo)".
So, when you're getting a list of pages or assets straight from a
Nanoc::Site instance, you should know that these are actual
Nanoc::Pages or Nanoc::Assets, and in order to get attributes off
them, you need to use attribute_named(:something).
I would love nothing more than to simply get rid of proxies entirely.
In retrospect, this was a bad design decision. Unfortunately, it's
hard to revert this one; if I suddenly start passing Pages (with an
appropriate method_missing) instead of PageProxies around, then I risk
getting backward compatibility issues.
This doesn't meant that it's impossible; it simply would require a lot
of thought to make sure everything still works (fortunately nanoc has
an extensive test case). It's definitely on my todo list! Possibly for
2.2...
2) A really annoying problem is also that my 'tags_for' links are all
now broken too when using the autocompiler. [..] But, in the second
line:
<a href="/tags/nanoc/">nanoc</a>
Gives a 404 when clicked on. If I instead type explicitly:
.../tags/nanoc/index.html it works fine and the page loads.
Is this a bug in the autocompiler? In Firefox?!?
A bug in the autocompiler. When requesting a path for which no page
exists (e.g. /tags/nanoc/), but which *does* contain an index filename
(e.g. index.html), then the autocompiler should serve the index.html
file.
This bug will be fixed soon. Thanks for letting me know! :)
Regards,
Denis
That's quite neat. I've added a link to that article on the nanoc Trac.
The original idea of generating placeholder tag pages is indeed much better than letting rake generate temporary pages and compile those. This is the technique I use for the archive pages for the nanoc site, but I'm not really liking it either, so I may actually change the way I create these archive pages some day.
By the way, "nanoc" is spelled "nanoc" and not "Nanoc", i.e. a lowercase n. :)
Thanks Denis - feel free to rip off anything you want from it.
I'm happy with using placeholder pages for now - seems to work pretty
well and I do like the fact it is explicit, so I can see nanoc updating
the indices etc. when things change - gives me confidence it is
actually working :)
> By the way, "nanoc" is spelled "nanoc" and not "Nanoc", i.e. a
> lowercase n. :)
Thanks - I'll go through and correct my articles :)
BTW: I have it on good authority from a friend of mine that the Sass
asset fix works from the 2.1.3 release - many many thanks for the quick
fix!
That's quite neat. I've added a link to that article on the nanoc Trac.
The original idea of generating placeholder tag pages is indeed much
better than letting rake generate temporary pages and compile those.
This is the technique I use for the archive pages for the nanoc site,
but I'm not really liking it either, so I may actually change the way
I create these archive pages some day.
By the way, "nanoc" is spelled "nanoc" and not "Nanoc", i.e. a
lowercase n. :)
Regards,
Denis