2 package IkiWiki::Plugin::autoindex;
10 hook(type => "getsetup", id => "autoindex", call => \&getsetup);
11 hook(type => "refresh", id => "autoindex", call => \&refresh);
14 sub getsetup () { #{{{
22 sub genindex ($) { #{{{
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}) {
43 if (IkiWiki::file_pruned($_, $dir)) {
47 my ($f)=/$config{wiki_file_regexp}/; # untaint
48 return unless defined $f;
50 return unless length $f;
51 return if $f =~ /\._([^.]+)$/; # skip internal page
53 $pages{pagename($f)}=1;
55 elsif ($dir eq $config{srcdir}) {
64 if (ref $pagestate{index}{autoindex}{deleted}) {
65 %deleted=%{$pagestate{index}{autoindex}{deleted}};
66 foreach my $dir (keys %deleted) {
67 # remove deleted page state if the deleted page is re-added,
68 # or if all its subpages are deleted
69 if ($deleted{$dir} && (exists $pages{$dir} ||
70 ! grep /^$dir\/.*/, keys %pages)) {
71 delete $deleted{$dir};
74 $pagestate{index}{autoindex}{deleted}=\%deleted;
78 foreach my $dir (keys %dirs) {
79 if (! exists $pages{$dir} && ! $deleted{$dir} &&
80 grep /^$dir\/.*/, keys %pages) {
81 if (exists $IkiWiki::pagemtime{$dir}) {
82 # This page must have just been deleted, so
83 # don't re-add it. And remember it was
85 if (! ref $pagestate{index}{autoindex}{deleted}) {
86 $pagestate{index}{autoindex}{deleted}={};
88 ${$pagestate{index}{autoindex}{deleted}}{$dir}=1;
98 IkiWiki::disable_commit_hook();
100 genindex($_) foreach @needed;
102 IkiWiki::rcs_commit_staged(
103 gettext("automatic index generation"),
105 IkiWiki::enable_commit_hook();