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}) {
67 next if $dir eq $IkiWiki::Plugin::transient::transientdir;
73 my $file=decode_utf8($_);
75 return unless length $file;
76 if (IkiWiki::file_pruned($file)) {
80 my ($f) = $file =~ /$config{wiki_file_regexp}/; # untaint
81 return unless defined $f;
82 return if $f =~ /\._([^.]+)$/; # skip internal page
84 $pages{pagename($f)}=1;
86 elsif ($dir eq $config{srcdir}) {
93 chdir($origdir) || die "chdir $origdir: $!";
98 # {deleted} contains pages that have been deleted at some point.
99 # This plugin used to delete from the hash sometimes, but no longer
100 # does; in [[todo/autoindex_should_use_add__95__autofile]] Joey
101 # thought the old behaviour was probably a bug.
103 # The effect of listing a page in {deleted} was to avoid re-creating
104 # it; we migrate these pages to {autofile} which has the same effect.
105 # However, {autofile} contains source filenames whereas {deleted}
106 # contains page names.
108 if (ref $wikistate{autoindex}{deleted}) {
109 %deleted=%{$wikistate{autoindex}{deleted}};
110 delete $wikistate{autoindex}{deleted};
112 elsif (ref $pagestate{index}{autoindex}{deleted}) {
113 # an even older version
114 %deleted=%{$pagestate{index}{autoindex}{deleted}};
115 delete $pagestate{index}{autoindex};
119 foreach my $dir (keys %deleted) {
120 my $file=newpagefile($dir, $config{default_pageext});
121 $wikistate{autoindex}{autofile}{$file} = 1;
125 foreach my $dir (keys %dirs) {
126 if (! exists $pages{$dir} && grep /^$dir\/.*/, keys %pages) {