diff options
author | Joey Hess <joey@kitenet.net> | 2010-04-17 12:50:23 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2010-04-17 12:50:23 -0400 |
commit | 54f600af14bf6dc067ffc30ec6f22d517001fe99 (patch) | |
tree | ddd20f6f03bc376700f8ebac24f360bf1fe3b269 /IkiWiki/Plugin | |
parent | 7fcc0faf8367c5ae64a3ff06d0d74baa063c4dfc (diff) | |
parent | 981400177d68a279f485727be3f013e68f0bf691 (diff) |
Merge remote branch 'davrieb/autotag' into autotag
Conflicts:
IkiWiki.pm
IkiWiki/Plugin/tag.pm
Diffstat (limited to 'IkiWiki/Plugin')
-rw-r--r-- | IkiWiki/Plugin/tag.pm | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/IkiWiki/Plugin/tag.pm b/IkiWiki/Plugin/tag.pm index 7a85874f6..9e6f417bf 100644 --- a/IkiWiki/Plugin/tag.pm +++ b/IkiWiki/Plugin/tag.pm @@ -34,6 +34,13 @@ sub getsetup () { safe => 1, rebuild => 1, }, + tag_autocreate => { + type => "boolean", + example => 0, + description => "Autocreate new tag pages", + safe => 1, + rebuild => 1, + }, } sub tagpage ($) { @@ -57,6 +64,22 @@ sub taglink ($$$;@) { return htmllink($page, $destpage, tagpage($tag), %opts); } +sub gentag ($) { + my $tag=shift; + if (defined $config{tag_autocreate} && $config{tag_autocreate}) { + my $tagfile = newpagefile(tagpage($tag), $config{default_pageext}); + $tagfile=~s/^\///; + + return if (! add_autofile($tagfile, "tag")); + + 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 ""; |