From f35d35abe36166893f68061a1fcb2a26bc056fbc Mon Sep 17 00:00:00 2001 From: David Riebenbauer Date: Sat, 30 Jan 2010 18:22:32 +0100 Subject: Automatically create tag pages, if "tag_autocreate=1" is set in the configuration. The pages will be created in tagbase, if and only if they do not exist in the srcdir yet. Tag pages will be create from "autotag.tmpl". At this stage a second refresh is needed for the tag pages to be rendered. Add autotag.tmpl template. --- IkiWiki/Plugin/tag.pm | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/tag.pm b/IkiWiki/Plugin/tag.pm index cdcfaf536..6c43a053d 100644 --- a/IkiWiki/Plugin/tag.pm +++ b/IkiWiki/Plugin/tag.pm @@ -36,6 +36,13 @@ sub getsetup () { safe => 1, rebuild => 1, }, + tag_autocreate => { + type => "boolean", + example => 0, + description => "Autocreate new tag pages", + safe => 1, + rebuild => 1, + }, } sub tagpage ($) { @@ -59,6 +66,21 @@ 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 (srcfile($tagfile,1)); + + 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 ""; @@ -72,6 +94,10 @@ sub preprocess_tag (@) { foreach my $tag (keys %params) { $tag=linkpage($tag); $tags{$page}{$tag}=1; + + # add tagpage if necessary + gentag($tag); + # hidden WikiLink add_link($page, tagpage($tag)); } -- cgit v1.2.3 From a8d313aba1094fc6d976c9ba3d09f58b768435c5 Mon Sep 17 00:00:00 2001 From: David Riebenbauer Date: Sun, 31 Jan 2010 01:12:20 +0100 Subject: Use add_autofile() in tag.pm to make the automatically created tagpages render. --- IkiWiki/Plugin/tag.pm | 2 ++ 1 file changed, 2 insertions(+) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/tag.pm b/IkiWiki/Plugin/tag.pm index 6c43a053d..90833fd9c 100644 --- a/IkiWiki/Plugin/tag.pm +++ b/IkiWiki/Plugin/tag.pm @@ -78,6 +78,8 @@ sub gentag ($) { my $template=template("autotag.tmpl"); $template->param(tag => $tag); writefile($tagfile, $config{srcdir}, $template->output); + + IkiWiki::add_autofile("$config{srcdir}/$tagfile"); } } -- cgit v1.2.3 From 25741100b0a0d81ae5113dfabe5a1ed84cdf8746 Mon Sep 17 00:00:00 2001 From: David Riebenbauer Date: Tue, 2 Feb 2010 12:12:23 +0100 Subject: Export add_autofile() for use in Plugins. --- IkiWiki.pm | 2 +- IkiWiki/Plugin/tag.pm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki.pm b/IkiWiki.pm index ad9fb7c79..7d7f430b3 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -23,7 +23,7 @@ our @EXPORT = qw(hook debug error template htmlpage deptype htmllink readfile writefile pagetype srcfile pagename displaytime will_render gettext urlto targetpage add_underlay pagetitle titlepage linkpage newpagefile - inject add_link + inject add_link add_autofile %config %links %pagestate %wikistate %renderedfiles %pagesources %destsources); our $VERSION = 3.00; # plugin interface version, next is ikiwiki version diff --git a/IkiWiki/Plugin/tag.pm b/IkiWiki/Plugin/tag.pm index 90833fd9c..c0b7feb23 100644 --- a/IkiWiki/Plugin/tag.pm +++ b/IkiWiki/Plugin/tag.pm @@ -79,7 +79,7 @@ sub gentag ($) { $template->param(tag => $tag); writefile($tagfile, $config{srcdir}, $template->output); - IkiWiki::add_autofile("$config{srcdir}/$tagfile"); + add_autofile("$config{srcdir}/$tagfile"); } } -- cgit v1.2.3 From a358d74bef51dae31332ff27e897fe04834571e6 Mon Sep 17 00:00:00 2001 From: David Riebenbauer Date: Wed, 3 Feb 2010 04:29:10 +0100 Subject: Check for existence off srcfile in add_autofile add_autofile has to have checks, whether to create the file, anyway, so this will make things more consistent. Correcter check for the result of verify_src_file(). Cosmetic rename of a variable $addfile to $autofile. --- IkiWiki.pm | 11 ++++++++--- IkiWiki/Plugin/tag.pm | 5 ++--- 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki.pm b/IkiWiki.pm index 90e623330..56c491339 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -1897,9 +1897,14 @@ sub add_link ($$) { } sub add_autofile ($) { - my $addfile=shift; - my ($file,$page) = verify_src_file($addfile,$config{srcdir}); - if ($page) { + my $autofile=shift; + + if (srcfile($autofile, 1)) { + return 0; + } + + my ($file, $page) = verify_src_file("$config{srcdir}/$autofile", $config{srcdir}); + if (defined $file) { push @autofiles, $file; } } diff --git a/IkiWiki/Plugin/tag.pm b/IkiWiki/Plugin/tag.pm index c0b7feb23..c6c99ae45 100644 --- a/IkiWiki/Plugin/tag.pm +++ b/IkiWiki/Plugin/tag.pm @@ -71,15 +71,14 @@ sub gentag ($) { if (defined $config{tag_autocreate} && $config{tag_autocreate}) { my $tagfile = newpagefile(tagpage($tag), $config{default_pageext}); $tagfile=~s/^\///; - return if (srcfile($tagfile,1)); + + return if (! add_autofile($tagfile)); debug(sprintf(gettext("creating tag page %s"), $tag)); my $template=template("autotag.tmpl"); $template->param(tag => $tag); writefile($tagfile, $config{srcdir}, $template->output); - - add_autofile("$config{srcdir}/$tagfile"); } } -- cgit v1.2.3 From 981400177d68a279f485727be3f013e68f0bf691 Mon Sep 17 00:00:00 2001 From: David Riebenbauer Date: Sat, 3 Apr 2010 21:10:16 +0200 Subject: Make sure deleted tag pages don't get recreated. The reason to do this is basically a user interaction design decision. It is achieved by adding an entry, associated to the creating plugin, to %pagestate. To find out if files were deleted a new global hash %del_hash is %introduced. --- IkiWiki.pm | 19 +++++++++++++++---- IkiWiki/Plugin/tag.pm | 2 +- IkiWiki/Render.pm | 5 ++++- 3 files changed, 20 insertions(+), 6 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki.pm b/IkiWiki.pm index 1770703a5..966a3bbc6 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -14,7 +14,7 @@ use open qw{:utf8 :std}; use vars qw{%config %links %oldlinks %pagemtime %pagectime %pagecase %pagestate %wikistate %renderedfiles %oldrenderedfiles %pagesources %destsources %depends %depends_simple %hooks - %forcerebuild %loaded_plugins @autofiles}; + %forcerebuild %loaded_plugins %autofiles %del_hash}; use Exporter q{import}; our @EXPORT = qw(hook debug error template htmlpage deptype @@ -1895,17 +1895,28 @@ sub add_link ($$) { unless grep { $_ eq $link } @{$links{$page}}; } -sub add_autofile ($) { +sub add_autofile ($$) { my $autofile=shift; + my $plugin=shift; if (srcfile($autofile, 1)) { return 0; } my ($file, $page) = verify_src_file("$config{srcdir}/$autofile", $config{srcdir}); - if (defined $file) { - push @autofiles, $file; + + if ((!defined $file) || + (exists $pagestate{$page}{$plugin}{autofile_deleted})) { + return 0; + } + + if (exists $del_hash{$file}) { + $pagestate{$page}{$plugin}{autofile_deleted}=1; + return 0; } + + $autofiles{$file}=$plugin; + return 1; } sub pagespec_translate ($) { diff --git a/IkiWiki/Plugin/tag.pm b/IkiWiki/Plugin/tag.pm index c6c99ae45..fdd63d637 100644 --- a/IkiWiki/Plugin/tag.pm +++ b/IkiWiki/Plugin/tag.pm @@ -72,7 +72,7 @@ sub gentag ($) { my $tagfile = newpagefile(tagpage($tag), $config{default_pageext}); $tagfile=~s/^\///; - return if (! add_autofile($tagfile)); + return if (! add_autofile($tagfile, "tag")); debug(sprintf(gettext("creating tag page %s"), $tag)); diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm index fc71c8919..0c21455fb 100644 --- a/IkiWiki/Render.pm +++ b/IkiWiki/Render.pm @@ -637,12 +637,14 @@ sub refresh () { my ($changed, $internal_changed)=find_changed($files); run_hooks(needsbuild => sub { shift->($changed) }); my $oldlink_targets=calculate_old_links($changed, $del); + %del_hash = map { $_ => 1 } @{$del}; foreach my $file (@$changed) { scan($file); } - while (my $autofile = shift (@autofiles)) { + while (my $autofile = shift @{[keys %autofiles]}) { + my $plugin=$autofiles{$autofile}; my $page=pagename($autofile); if ($pages->{$page}) { debug(sprintf(gettext("%s has multiple possible source pages"), $page)); @@ -654,6 +656,7 @@ sub refresh () { push @{$changed}, $autofile if find_changed([$autofile]); scan($autofile); + delete $autofiles{$autofile}; } calculate_links(); -- cgit v1.2.3