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 () {
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}};
}
if (@needed) {
- if ($config{rcs}) {
- IkiWiki::disable_commit_hook();
- }
foreach my $page (@needed) {
genindex($page);
}
- if ($config{rcs}) {
- IkiWiki::rcs_commit_staged(
- message => gettext("automatic index generation"),
- );
- IkiWiki::enable_commit_hook();
- }
}
}
use warnings;
use strict;
-use Test::More tests => 22;
+use Test::More tests => 28;
BEGIN { use_ok("IkiWiki"); }
BEGIN { use_ok("IkiWiki::Render"); }
# "gone" disappeared just before this refresh pass so it still has a mtime
$pagemtime{gone} = $pagectime{gone} = 1000000;
+my %pages;
+my @del;
+
IkiWiki::Plugin::autoindex::refresh();
# these pages are still on record as having been deleted, because they have
ok(! exists $wikistate{autoindex}{deleted}{reinstated});
ok(! -f "t/tmp/reinstated.mdwn");
-# needs creating
+# needs creating (deferred; part of the autofile mechanism now)
ok(! exists $wikistate{autoindex}{deleted}{tags});
+%pages = ();
+@del = ();
+is($autofiles{"tags.mdwn"}{plugin}, "autoindex");
+IkiWiki::gen_autofile("tags.mdwn", \%pages, \@del);
+is_deeply(\%pages, {"t/tmp/tags" => 1}) || diag explain \%pages;
+is_deeply(\@del, []) || diag explain \@del;
ok(-s "t/tmp/tags.mdwn");
# needs creating because of an attachment
ok(! exists $wikistate{autoindex}{deleted}{attached});
+%pages = ();
+@del = ();
+is($autofiles{"attached.mdwn"}{plugin}, "autoindex");
+IkiWiki::gen_autofile("attached.mdwn", \%pages, \@del);
+is_deeply(\%pages, {"t/tmp/attached" => 1}) || diag explain \%pages;
+is_deeply(\@del, []) || diag explain \@del;
ok(-s "t/tmp/attached.mdwn");
1;