Tagging and trailing slash

38 views
Skip to first unread message

bdillahu

unread,
Oct 15, 2009, 11:37:35 PM10/15/09
to nanoc
OK, I don't understand (but that's nothing new).

Been setting up my little site and been copying a log of h3rald and
some other sites. Thanks SO much for posting your code!

Anyhow, have things working so that I can generate tags, etc. The
problem is that the code in tagging.rb:

def link_for_tag(tag, base_url)
%[<a href="#{base_url}#{tag}" rel="tag">#{tag}</a>]
end

Has no trailing slash on the tag link.

If I change it to

def link_for_tag(tag, base_url)
%[<a href="#{base_url}#{tag}/" rel="tag">#{tag}</a>]
end

it works, but it seems like I shouldn't need to do that. He3rald's
site works (online) without it, but if I clone it down to my machine,
it doesn't work.

Is this something about relative links and working locally and it will
all "just work" if I publish it?

Thanks!

Bruce

bdillahu

unread,
Oct 16, 2009, 9:09:12 AM10/16/09
to nanoc
Well, just to answer myself, partly... if I publish it, apache makes
the lack of the slash ok, which should have dawned on me before hand.

Duh...

Denis Defreyne

unread,
Oct 17, 2009, 7:15:41 AM10/17/09
to na...@googlegroups.com
On 16 Oct 2009, at 05:37, bdillahu wrote:

> The problem is that the code in tagging.rb:
>
> def link_for_tag(tag, base_url)
> %[<a href="#{base_url}#{tag}" rel="tag">#{tag}</a>]
> end
>
> Has no trailing slash on the tag link.

Hi,

This should usually not be a problem (web servers will redirect from
the /-less URL to the /-ful URL) but it is probably best if you modify
the code so that it adds the trailing slash. h3rald uses a custom
Tagging helper which does this; this modified Tagging helper
implements #tags_for like this (in lib/helpers.rb):

def tags_for(article)
article.attributes[:tags].map do |t|
%{<a class="tag" href="/tags/#{t}/">#{t}</a>}
end.join " &middot; "
end

Generally speaking, nanoc's helpers are provided for convenience, but
they are by no means always the most powerful or the most feature-
complete. If you feel that some helper doesn't quite suit your needs,
by all means take the code and tweak it until it works for you! :)

Regards,

Denis

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

bdillahu

unread,
Oct 18, 2009, 3:56:53 PM10/18/09
to nanoc
Thanks Denis... appreciate the advice and most especially the tool and
all the help!

Bruce

On Oct 17, 7:15 am, Denis Defreyne <denis.defre...@stoneship.org>
wrote:
> denis.defre...@stoneship.org
Reply all
Reply to author
Forward
0 new messages