2 package IkiWiki::Plugin::autoindex;
10 hook(type => "getsetup", id => "autoindex", call => \&getsetup);
11 hook(type => "refresh", id => "autoindex", call => \&refresh);
12 IkiWiki::loadplugin("transient");
25 description => "commit autocreated index pages",
33 my $file=newpagefile($page, $config{default_pageext});
35 add_autofile($file, "autoindex", sub {
36 my $message = sprintf(gettext("creating index page %s"),
40 my $dir = $config{srcdir};
41 if (! $config{autoindex_commit}) {
42 $dir = $IkiWiki::Plugin::transient::transientdir;
45 my $template = template("autoindex.tmpl");
46 $template->param(page => $page);
47 writefile($file, $dir, $template->output);
49 if ($config{rcs} && $config{autoindex_commit}) {
50 IkiWiki::disable_commit_hook();
51 IkiWiki::rcs_add($file);
52 IkiWiki::rcs_commit_staged(message => $message);
53 IkiWiki::enable_commit_hook();
59 eval q{use File::Find};
66 foreach my $dir ($config{srcdir}, @{$config{underlaydirs}}, $config{underlaydir}) {
72 my $file=decode_utf8($_);
74 return unless length $file;
75 if (IkiWiki::file_pruned($file)) {
79 my ($f) = $file =~ /$config{wiki_file_regexp}/; # untaint
80 return unless defined $f;
81 return if $f =~ /\._([^.]+)$/; # skip internal page
83 $pages{pagename($f)}=1;
85 elsif ($dir eq $config{srcdir}) {
92 chdir($origdir) || die "chdir $origdir: $!";
97 # {deleted} contains pages that have been deleted at some point.
98 # This plugin used to delete from the hash sometimes, but no longer
99 # does; in [[todo/autoindex_should_use_add__95__autofile]] Joey
100 # thought the old behaviour was probably a bug.
102 # The effect of listing a page in {deleted} was to avoid re-creating
103 # it; we migrate these pages to {autofile} which has the same effect.
104 # However, {autofile} contains source filenames whereas {deleted}
105 # contains page names.
107 if (ref $wikistate{autoindex}{deleted}) {
108 %deleted=%{$wikistate{autoindex}{deleted}};
109 delete $wikistate{autoindex}{deleted};
111 elsif (ref $pagestate{index}{autoindex}{deleted}) {
112 # an even older version
113 %deleted=%{$pagestate{index}{autoindex}{deleted}};
114 delete $pagestate{index}{autoindex};
118 foreach my $dir (keys %deleted) {
119 my $file=newpagefile($dir, $config{default_pageext});
120 $wikistate{autoindex}{autofile}{$file} = 1;
124 foreach my $dir (keys %dirs) {
125 if (! exists $pages{$dir} && grep /^$dir\/.*/, keys %pages) {