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};
38 foreach my $dir ($config{srcdir}, @{$config{underlaydirs}}, $config{underlaydir}) {
40 $dir=File::Spec->canonpath($dir);
45 my $file=File::Spec->canonpath(decode_utf8($_));
46 return if $file eq $dir;
47 $file=~s/^\Q$dir\E\/?//;
48 return unless length $file;
49 if (IkiWiki::file_pruned($file)) {
53 my ($f) = $file =~ /$config{wiki_file_regexp}/; # untaint
54 return unless defined $f;
55 return if $f =~ /\._([^.]+)$/; # skip internal page
57 $pages{pagename($f)}=1;
59 elsif ($dir eq $config{srcdir}) {
68 if (ref $wikistate{autoindex}{deleted}) {
69 %deleted=%{$wikistate{autoindex}{deleted}};
71 elsif (ref $pagestate{index}{autoindex}{deleted}) {
73 %deleted=%{$pagestate{index}{autoindex}{deleted}};
74 delete $pagestate{index}{autoindex};
78 foreach my $dir (keys %deleted) {
79 # remove deleted page state if the deleted page is re-added,
80 # or if all its subpages are deleted
81 if ($deleted{$dir} && (exists $pages{$dir} ||
82 ! grep /^$dir\/.*/, keys %pages)) {
83 delete $deleted{$dir};
86 $wikistate{autoindex}{deleted}=\%deleted;
90 foreach my $dir (keys %dirs) {
91 if (! exists $pages{$dir} && ! $deleted{$dir} &&
92 grep /^$dir\/.*/, keys %pages) {
93 if (exists $IkiWiki::pagemtime{$dir}) {
94 # This page must have just been deleted, so
95 # don't re-add it. And remember it was
97 if (! ref $wikistate{autoindex}{deleted}) {
98 $wikistate{autoindex}{deleted}={};
100 ${$wikistate{autoindex}{deleted}}{$dir}=1;
110 IkiWiki::disable_commit_hook();
112 foreach my $page (@needed) {
116 IkiWiki::rcs_commit_staged(
117 gettext("automatic index generation"),
119 IkiWiki::enable_commit_hook();