From 3a983f12dc73f739532e7bd4c00d5910c8d01ee2 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Mon, 12 Apr 2010 23:53:17 +0200 Subject: [PATCH] Template support for tagtypes --- IkiWiki/Plugin/tag.pm | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/IkiWiki/Plugin/tag.pm b/IkiWiki/Plugin/tag.pm index 8775e5432..1176226b4 100644 --- a/IkiWiki/Plugin/tag.pm +++ b/IkiWiki/Plugin/tag.pm @@ -38,7 +38,7 @@ sub getsetup () { tagtypes => { type => "string", example => ["category", "column"], - description => "extra categorization types, behaving like tags but separate from them", + description => "extra categorization types: they define a new directive each, with a corresponding template parameter and link type", safe => 1, rebuild => 1, } @@ -147,18 +147,39 @@ sub pagetemplate (@) { my $template=$params{template}; my $tags = $typedlinks{$page}{tag}; + my @taglist = (); + + if (defined $tags && %$tags) { + push @taglist, keys %$tags; + $template->param(tags => [ + map { + link => taglink($page, $destpage, $_, 'tag', rel => "tag") + }, sort keys %$tags + ]) if $template->query(name => "tags"); + } - $template->param(tags => [ - map { - link => taglink($page, $destpage, $_, 'tag', rel => "tag") - }, sort keys %$tags - ]) if defined $tags && %$tags && $template->query(name => "tags"); + # custom tagtypes have a separate treatment for a number of reasons, including the fact that + # their template parameter name is different from the tag/link type ('tags' vs 'tag') + # notice the use of rel => $tagtype + foreach my $tagtype (tagtypes()) { + $tags = $typedlinks{$page}{$tagtype}; + if (defined $tags && %$tags) { + push @taglist, keys %$tags; + $template->param($tagtype => [ + map { + link => taglink($page, $destpage, $_, $tagtype, rel => $tagtype) + }, sort keys %$tags + ]) if $template->query(name => $tagtype); + } + } + + debug(join ',', @taglist); if ($template->query(name => "categories")) { # It's an rss/atom template. Add any categories. - if (defined $tags && %$tags) { + if (@taglist) { $template->param(categories => [map { category => $_ }, - sort keys %$tags]); + sort @taglist]); } } } -- 2.32.0.93.g670b81a890