X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/6d063a6698ad72476d9243956b0f13ec33a09dbd..dca6679a5442581746daf89e78ee83712a017b98:/IkiWiki/Plugin/autoindex.pm diff --git a/IkiWiki/Plugin/autoindex.pm b/IkiWiki/Plugin/autoindex.pm index 1d0612e84..ba2dcb907 100644 --- a/IkiWiki/Plugin/autoindex.pm +++ b/IkiWiki/Plugin/autoindex.pm @@ -22,29 +22,47 @@ sub getsetup () { sub genindex ($) { my $page=shift; my $file=newpagefile($page, $config{default_pageext}); - my $template=template("autoindex.tmpl"); - $template->param(page => $page); - writefile($file, $config{srcdir}, $template->output); - if ($config{rcs}) { - IkiWiki::rcs_add($file); - } + + add_autofile($file, "autoindex", sub { + my $message = sprintf(gettext("creating index page %s"), + $page); + debug($message); + + my $template = template("autoindex.tmpl"); + $template->param(page => $page); + writefile($file, $config{srcdir}, $template->output); + + if ($config{rcs}) { + IkiWiki::disable_commit_hook(); + IkiWiki::rcs_add($file); + IkiWiki::rcs_commit_staged(message => $message); + IkiWiki::enable_commit_hook(); + } + }); } sub refresh () { eval q{use File::Find}; error($@) if $@; + eval q{use Cwd}; + error($@) if $@; + my $origdir=getcwd(); my (%pages, %dirs); foreach my $dir ($config{srcdir}, @{$config{underlaydirs}}, $config{underlaydir}) { + chdir($dir) || next; + find({ no_chdir => 1, wanted => sub { - $_=decode_utf8($_); - if (IkiWiki::file_pruned($_)) { + my $file=decode_utf8($_); + $file=~s/^\.\/?//; + return unless length $file; + if (IkiWiki::file_pruned($file)) { $File::Find::prune=1; } elsif (! -l $_) { - my ($f)=/$config{wiki_file_regexp}/; # untaint + my ($f) = $file =~ /$config{wiki_file_regexp}/; # untaint return unless defined $f; return if $f =~ /\._([^.]+)$/; # skip internal page if (! -d _) { @@ -55,9 +73,14 @@ sub refresh () { } } } - }, $dir); + }, '.'); + + chdir($origdir) || die "chdir $origdir: $!"; } - + + # FIXME: some of this is probably redundant with add_autofile now, and + # the rest should perhaps be added to the autofile machinery + my %deleted; if (ref $wikistate{autoindex}{deleted}) { %deleted=%{$wikistate{autoindex}{deleted}}; @@ -100,18 +123,9 @@ sub refresh () { } if (@needed) { - if ($config{rcs}) { - IkiWiki::disable_commit_hook(); - } foreach my $page (@needed) { genindex($page); } - if ($config{rcs}) { - IkiWiki::rcs_commit_staged( - gettext("automatic index generation"), - undef, undef); - IkiWiki::enable_commit_hook(); - } } }