]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/Plugin/autoindex.pm
Update changelog
[git.ikiwiki.info.git] / IkiWiki / Plugin / autoindex.pm
index 5a58c820aaefa1244fd2b08947f82968ce945c37..d5ee4b58f3422344a3debae53dd334366ad43e18 100644 (file)
@@ -7,8 +7,10 @@ use IkiWiki 3.00;
 use Encode;
 
 sub import {
 use Encode;
 
 sub import {
+       hook(type => "checkconfig", id => "autoindex", call => \&checkconfig);
        hook(type => "getsetup", id => "autoindex", call => \&getsetup);
        hook(type => "refresh", id => "autoindex", call => \&refresh);
        hook(type => "getsetup", id => "autoindex", call => \&getsetup);
        hook(type => "refresh", id => "autoindex", call => \&refresh);
+       IkiWiki::loadplugin("transient");
 }
 
 sub getsetup () {
 }
 
 sub getsetup () {
@@ -17,6 +19,20 @@ sub getsetup () {
                        safe => 1,
                        rebuild => 0,
                },
                        safe => 1,
                        rebuild => 0,
                },
+               autoindex_commit => {
+                       type => "boolean",
+                       example => 1,
+                       default => 1,
+                       description => "commit autocreated index pages",
+                       safe => 1,
+                       rebuild => 0,
+               },
+}
+
+sub checkconfig () {
+       if (! defined $config{autoindex_commit}) {
+               $config{autoindex_commit} = 1;
+       }
 }
 
 sub genindex ($) {
 }
 
 sub genindex ($) {
@@ -28,11 +44,16 @@ sub genindex ($) {
                                $page);
                        debug($message);
 
                                $page);
                        debug($message);
 
+                       my $dir = $config{srcdir};
+                       if (! $config{autoindex_commit}) {
+                               $dir = $IkiWiki::Plugin::transient::transientdir;
+                       }
+
                        my $template = template("autoindex.tmpl");
                        $template->param(page => $page);
                        my $template = template("autoindex.tmpl");
                        $template->param(page => $page);
-                       writefile($file, $config{srcdir}, $template->output);
+                       writefile($file, $dir, $template->output);
 
 
-                       if ($config{rcs}) {
+                       if ($config{rcs} && $config{autoindex_commit}) {
                                IkiWiki::disable_commit_hook();
                                IkiWiki::rcs_add($file);
                                IkiWiki::rcs_commit_staged(message => $message);
                                IkiWiki::disable_commit_hook();
                                IkiWiki::rcs_add($file);
                                IkiWiki::rcs_commit_staged(message => $message);
@@ -68,7 +89,7 @@ sub refresh () {
                                        if (! -d _) {
                                                $pages{pagename($f)}=1;
                                        }
                                        if (! -d _) {
                                                $pages{pagename($f)}=1;
                                        }
-                                       elsif ($dir eq $config{srcdir}) {
+                                       elsif ($dir eq $config{srcdir} || ! $config{autoindex_commit}) {
                                                $dirs{$f}=1;
                                        }
                                }
                                                $dirs{$f}=1;
                                        }
                                }