2 package IkiWiki
::Plugin
::autoindex
;
10 hook
(type
=> "getsetup", id
=> "autoindex", call
=> \
&getsetup
);
11 hook
(type
=> "refresh", id
=> "autoindex", call
=> \
&refresh
);
24 my $file=newpagefile
($page, $config{default_pageext
});
25 my $template=template
("autoindex.tmpl");
26 $template->param(page
=> $page);
27 writefile
($file, $config{srcdir
}, $template->output);
29 IkiWiki
::rcs_add
($file);
34 eval q{use File::Find};
41 foreach my $dir ($config{srcdir
}, @
{$config{underlaydirs
}}, $config{underlaydir
}) {
47 my $file=decode_utf8
($_);
49 return unless length $file;
50 if (IkiWiki
::file_pruned
($file)) {
54 my ($f) = $file =~ /$config{wiki_file_regexp}/; # untaint
55 return unless defined $f;
56 return if $f =~ /\._([^.]+)$/; # skip internal page
58 $pages{pagename
($f)}=1;
60 elsif ($dir eq $config{srcdir
}) {
67 chdir($origdir) || die "chdir $origdir: $!";
71 if (ref $wikistate{autoindex
}{deleted
}) {
72 %deleted=%{$wikistate{autoindex
}{deleted
}};
74 elsif (ref $pagestate{index}{autoindex
}{deleted
}) {
76 %deleted=%{$pagestate{index}{autoindex
}{deleted
}};
77 delete $pagestate{index}{autoindex
};
81 foreach my $dir (keys %deleted) {
82 # remove deleted page state if the deleted page is re-added,
83 # or if all its subpages are deleted
84 if ($deleted{$dir} && (exists $pages{$dir} ||
85 ! grep /^$dir\/.*/, keys %pages)) {
86 delete $deleted{$dir};
89 $wikistate{autoindex
}{deleted
}=\
%deleted;
93 foreach my $dir (keys %dirs) {
94 if (! exists $pages{$dir} && ! $deleted{$dir} &&
95 grep /^$dir\/.*/, keys %pages) {
96 if (exists $IkiWiki::pagemtime
{$dir}) {
97 # This page must have just been deleted, so
98 # don't re-add it. And remember it was
100 if (! ref $wikistate{autoindex
}{deleted
}) {
101 $wikistate{autoindex
}{deleted
}={};
103 ${$wikistate{autoindex
}{deleted
}}{$dir}=1;
113 IkiWiki
::disable_commit_hook
();
115 foreach my $page (@needed) {
119 IkiWiki
::rcs_commit_staged
(
120 message
=> gettext
("automatic index generation"),
122 IkiWiki
::enable_commit_hook
();