]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Plugin/tag.pm
Merge branch 'ready/tag-test' into transient-tag
[ikiwiki.git] / IkiWiki / Plugin / tag.pm
index a7f37a5122b30da2a8716200093a98ef3aa6f189..fd5ce1e8a91488ce5d5b20709001fd3d177def97 100644 (file)
@@ -36,7 +36,7 @@ sub getsetup () {
                },
                tag_autocreate => {
                        type => "boolean",
-                       example => 0,
+                       example => 1,
                        description => "autocreate new tag pages?",
                        safe => 1,
                        rebuild => undef,
@@ -46,7 +46,7 @@ sub getsetup () {
 sub taglink ($) {
        my $tag=shift;
        
-       if ($tag !~ m{^\.?/} &&
+       if ($tag !~ m{^/} &&
            defined $config{tagbase}) {
                $tag="/".$config{tagbase}."/".$tag;
                $tag=~y#/#/#s; # squash dups
@@ -55,6 +55,17 @@ sub taglink ($) {
        return $tag;
 }
 
+# Returns a tag name from a tag link
+sub tagname ($) {
+       my $tag=shift;
+       if (defined $config{tagbase}) {
+               $tag =~ s!^/\Q$config{tagbase}\E/!!;
+       } else {
+               $tag =~ s!^\.?/!!;
+       }
+       return pagetitle($tag, 1);
+}
+
 sub htmllink_tag ($$$;@) {
        my $page=shift;
        my $destpage=shift;
@@ -67,7 +78,8 @@ sub htmllink_tag ($$$;@) {
 sub gentag ($) {
        my $tag=shift;
 
-       if ($config{tag_autocreate}) {
+       if ($config{tag_autocreate} ||
+           ($config{tagbase} && ! defined $config{tag_autocreate})) {
                my $tagpage=taglink($tag);
                if ($tagpage=~/^\.\/(.*)/) {
                        $tagpage=$1;
@@ -83,13 +95,13 @@ sub gentag ($) {
                        debug($message);
 
                        my $template=template("autotag.tmpl");
-                       $template->param(tagname => IkiWiki::basename($tag));
+                       $template->param(tagname => tagname($tag));
                        $template->param(tag => $tag);
                        writefile($tagfile, $config{srcdir}, $template->output);
                        if ($config{rcs}) {
                                IkiWiki::disable_commit_hook();
                                IkiWiki::rcs_add($tagfile);
-                               IkiWiki::rcs_commit_staged($message, undef, undef);
+                               IkiWiki::rcs_commit_staged(message => $message);
                                IkiWiki::enable_commit_hook();
                        }
                });
@@ -153,14 +165,15 @@ sub pagetemplate (@) {
 
        $template->param(tags => [
                map { 
-                       link => htmllink_tag($page, $destpage, $_, rel => "tag")
+                       link => htmllink_tag($page, $destpage, $_,
+                                       rel => "tag", linktext => tagname($_))
                }, sort keys %$tags
        ]) if defined $tags && %$tags && $template->query(name => "tags");
 
        if ($template->query(name => "categories")) {
                # It's an rss/atom template. Add any categories.
                if (defined $tags && %$tags) {
-                       $template->param(categories => [map { category => $_ },
+                       $template->param(categories => [map { category => tagname($_) },
                                sort keys %$tags]);
                }
        }