]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Plugin/tag.pm
tag_autocreate fixups
[ikiwiki.git] / IkiWiki / Plugin / tag.pm
index 7a85874f6e928e11e85ec57aee279b0d8197687c..1145a9f130966d4c69b1a6ce6b8373fdbaf0eafd 100644 (file)
@@ -34,6 +34,13 @@ sub getsetup () {
                        safe => 1,
                        rebuild => 1,
                },
+               tag_autocreate => {
+                       type => "boolean",
+                       example => 0,
+                       description => "autocreate new tag pages?",
+                       safe => 1,
+                       rebuild => undef,
+               },
 }
 
 sub tagpage ($) {
@@ -57,6 +64,22 @@ sub taglink ($$$;@) {
        return htmllink($page, $destpage, tagpage($tag), %opts);
 }
 
+sub gentag ($) {
+       my $tag=shift;
+       if ($config{tag_autocreate}) {
+               my $tagfile = newpagefile(tagpage($tag), $config{default_pageext});
+               $tagfile=~s/^\///;
+
+               add_autofile($tagfile, sub {
+                       debug(sprintf(gettext("creating tag page %s"), $tag));
+
+                       my $template=template("autotag.tmpl");
+                       $template->param(tag => $tag);
+                       writefile($tagfile, $config{srcdir}, $template->output);
+               });
+       }
+}
+
 sub preprocess_tag (@) {
        if (! @_) {
                return "";
@@ -69,8 +92,12 @@ sub preprocess_tag (@) {
 
        foreach my $tag (keys %params) {
                $tag=linkpage($tag);
+               
                # hidden WikiLink
                add_link($page, tagpage($tag), 'tag');
+               
+               # add tagpage if necessary
+               gentag($tag);
        }
                
        return "";