Allow creation of transient index pages for directories outside srcdir

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
master
Simon McVittie 2012-04-09 15:31:14 +01:00
parent fefc8f4dce
commit 17440ea301
2 changed files with 25 additions and 13 deletions

View 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;
}
}

View File

@ -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"});