Allow creation of transient index pages for directories outside srcdir
authorSimon McVittie <smcv@debian.org>
Mon, 9 Apr 2012 14:31:14 +0000 (15:31 +0100)
committerSimon McVittie <smcv@debian.org>
Fri, 4 Jul 2014 08:25:09 +0000 (09:25 +0100)
After this change autoindex creates index pages also for empty directories
included in underlays, but only if it isn't going to commit them to the
srcdir ($config{autoindex_commit} = 0).

Inspired by a patch from Tuomas Jormola.

Bug-Debian: http://bugs.debian.org/611068

IkiWiki/Plugin/autoindex.pm
t/autoindex.t

index 04d5014610dea28e1d069b67bb19601960c6284d..d5ee4b58f3422344a3debae53dd334366ad43e18 100644 (file)
@@ -89,7 +89,7 @@ sub refresh () {
                                        if (! -d _) {
                                                $pages{pagename($f)}=1;
                                        }
-                                       elsif ($dir eq $config{srcdir}) {
+                                       elsif ($dir eq $config{srcdir} || ! $config{autoindex_commit}) {
                                                $dirs{$f}=1;
                                        }
                                }
index 2c7a286f8bf00a475f5659319a0a6b4c144eb6fb..e25b617337fd816be5ead453d371b35cd5fc3223 100755 (executable)
@@ -3,7 +3,7 @@ package IkiWiki;
 
 use warnings;
 use strict;
-use Test::More tests => 44;
+use Test::More tests => 50;
 
 BEGIN { use_ok("IkiWiki"); }
 BEGIN { use_ok("IkiWiki::Render"); }
@@ -54,15 +54,15 @@ $pagemtime{"has_internal/internal"} = 123456789;
 $pagectime{"has_internal/internal"} = 123456789;
 writefile("has_internal/internal._aggregated", "t/tmp/in", "this page is internal");
 
-# a directory containing only a page in an underlay shouldn't be indexed
-# (arguably; see [[transient autocreated tagbase is not transient autoindexed]])
+# a directory containing only a page in an underlay is now indexed
+# (see [[transient autocreated tagbase is not transient autoindexed]])
 $pagesources{"has_underlay/underlay"} = "has_underlay/underlay.mdwn";
 $pagemtime{"has_underlay/underlay"} = 123456789;
 $pagectime{"has_underlay/underlay"} = 123456789;
 writefile("has_underlay/underlay.mdwn", "t/tmp/underlay", "this page is in an underlay");
 
-# a directory containing only a transient page shouldn't be indexed
-# (arguably; see [[transient autocreated tagbase is not transient autoindexed]])
+# a directory containing only a transient page is now indexed
+# (see [[transient autocreated tagbase is not transient autoindexed]])
 $pagesources{"has_transient/transient"} = "has_transient/transient.mdwn";
 $pagemtime{"has_transient/transient"} = 123456789;
 $pagectime{"has_transient/transient"} = 123456789;
@@ -117,24 +117,36 @@ ok(! exists $wikistate{autoindex}{autofile}{"has_internal.mdwn"});
 ok(! exists $autofiles{"has_internal.mdwn"});
 ok(! -f "t/tmp/in/has_internal.mdwn");
 
-# a directory containing only a page in an underlay shouldn't be indexed
-# (arguably; see [[transient autocreated tagbase is not transient autoindexed]])
+# a directory containing only a page in an underlay is now indexed
+# (see [[transient autocreated tagbase is not transient autoindexed]])
 ok(! exists $wikistate{autoindex}{autofile}{"has_underlay.mdwn"});
-ok(! exists $autofiles{"has_underlay.mdwn"});
+is($autofiles{"has_underlay.mdwn"}{plugin}, "autoindex");
+%pages = ();
+@del = ();
+IkiWiki::gen_autofile("has_underlay.mdwn", \%pages, \@del);
+is_deeply(\%pages, {"t/tmp/in/has_underlay" => 1});
+is_deeply(\@del, []);
 ok(! -f "t/tmp/in/has_underlay.mdwn");
+ok(-s "t/tmp/in/.ikiwiki/transient/has_underlay.mdwn");
 
-# a directory containing only a transient page shouldn't be indexed
-# (arguably; see [[transient autocreated tagbase is not transient autoindexed]])
+# a directory containing only a transient page is now indexed
+# (see [[transient autocreated tagbase is not transient autoindexed]])
 ok(! exists $wikistate{autoindex}{autofile}{"has_transient.mdwn"});
-ok(! exists $autofiles{"has_transient.mdwn"});
+is($autofiles{"has_transient.mdwn"}{plugin}, "autoindex");
+%pages = ();
+@del = ();
+IkiWiki::gen_autofile("has_transient.mdwn", \%pages, \@del);
+is_deeply(\%pages, {"t/tmp/in/has_transient" => 1});
+is_deeply(\@del, []);
 ok(! -f "t/tmp/in/has_transient.mdwn");
+ok(-s "t/tmp/in/.ikiwiki/transient/has_transient.mdwn");
 
 # this page was re-created, but that no longer gets a special case
 # (see [[todo/autoindex_should_use_add__95__autofile]]) so it's the same as
 # deleted
 is($wikistate{autoindex}{autofile}{"reinstated.mdwn"}, 1);
 ok(! exists $autofiles{"reinstated.mdwn"});
-ok(! -f "t/tmp/in/reinstated.mdwn");
+ok(! -f "t/tmp/in/.ikiwiki/transient/reinstated.mdwn");
 
 # needs creating (deferred; part of the autofile mechanism now)
 ok(! exists $wikistate{autoindex}{autofile}{"tags.mdwn"});