2 package IkiWiki::Plugin::autoindex;
10 hook(type => "checkconfig", id => "autoindex", call => \&checkconfig);
11 hook(type => "getsetup", id => "autoindex", call => \&getsetup);
12 hook(type => "refresh", id => "autoindex", call => \&refresh);
13 IkiWiki::loadplugin("transient");
26 description => "commit autocreated index pages",
33 if (! defined $config{autoindex_commit}) {
34 $config{autoindex_commit} = 1;
40 my $file=newpagefile($page, $config{default_pageext});
42 add_autofile($file, "autoindex", sub {
43 my $message = sprintf(gettext("creating index page %s"),
47 my $dir = $config{srcdir};
48 if (! $config{autoindex_commit}) {
49 $dir = $IkiWiki::Plugin::transient::transientdir;
52 my $template = template("autoindex.tmpl");
53 $template->param(page => $page);
54 writefile($file, $dir, $template->output);
56 if ($config{rcs} && $config{autoindex_commit}) {
57 IkiWiki::disable_commit_hook();
58 IkiWiki::rcs_add($file);
59 IkiWiki::rcs_commit_staged(message => $message);
60 IkiWiki::enable_commit_hook();
66 eval q{use File::Find};
73 foreach my $dir ($config{srcdir}, @{$config{underlaydirs}}, $config{underlaydir}) {
79 my $file=decode_utf8($_);
81 return unless length $file;
82 if (IkiWiki::file_pruned($file)) {
86 my ($f) = $file =~ /$config{wiki_file_regexp}/; # untaint
87 return unless defined $f;
88 return if $f =~ /\._([^.]+)$/; # skip internal page
90 $pages{pagename($f)}=1;
92 elsif ($dir eq $config{srcdir} || ! $config{autoindex_commit}) {
99 chdir($origdir) || die "chdir $origdir: $!";
102 # Compatibility code.
104 # {deleted} contains pages that have been deleted at some point.
105 # This plugin used to delete from the hash sometimes, but no longer
106 # does; in [[todo/autoindex_should_use_add__95__autofile]] Joey
107 # thought the old behaviour was probably a bug.
109 # The effect of listing a page in {deleted} was to avoid re-creating
110 # it; we migrate these pages to {autofile} which has the same effect.
111 # However, {autofile} contains source filenames whereas {deleted}
112 # contains page names.
114 if (ref $wikistate{autoindex}{deleted}) {
115 %deleted=%{$wikistate{autoindex}{deleted}};
116 delete $wikistate{autoindex}{deleted};
118 elsif (ref $pagestate{index}{autoindex}{deleted}) {
119 # an even older version
120 %deleted=%{$pagestate{index}{autoindex}{deleted}};
121 delete $pagestate{index}{autoindex};
125 foreach my $dir (keys %deleted) {
126 my $file=newpagefile($dir, $config{default_pageext});
127 $wikistate{autoindex}{autofile}{$file} = 1;
131 foreach my $dir (keys %dirs) {
132 if (! exists $pages{$dir} && grep /^$dir\/.*/, keys %pages) {