summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--IkiWiki.pm29
-rw-r--r--IkiWiki/Plugin/aggregate.pm20
-rw-r--r--IkiWiki/Plugin/autoindex.pm2
-rw-r--r--IkiWiki/Plugin/editpage.pm6
-rw-r--r--IkiWiki/Plugin/rename.pm28
-rw-r--r--debian/changelog5
-rw-r--r--doc/plugins/write.mdwn6
-rw-r--r--doc/todo/index.html_allowed.mdwn4
8 files changed, 67 insertions, 33 deletions
diff --git a/IkiWiki.pm b/IkiWiki.pm
index 9b7baa0ee..34b315bbc 100644
--- a/IkiWiki.pm
+++ b/IkiWiki.pm
@@ -20,7 +20,7 @@ use Exporter q{import};
our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match
bestlink htmllink readfile writefile pagetype srcfile pagename
displaytime will_render gettext urlto targetpage
- add_underlay pagetitle titlepage linkpage
+ add_underlay pagetitle titlepage linkpage newpagefile
%config %links %pagestate %wikistate %renderedfiles
%pagesources %destsources);
our $VERSION = 2.00; # plugin interface version, next is ikiwiki version
@@ -198,6 +198,13 @@ sub getsetup () { #{{{
safe => 0, # changing requires manual transition
rebuild => 1,
},
+ indexpages => {
+ type => "boolean",
+ defualt => 0,
+ description => "use page/index.mdwn source files",
+ safe => 1,
+ rebuild => 1,
+ },
discussion => {
type => "boolean",
default => 1,
@@ -619,16 +626,32 @@ sub pagename ($) { #{{{
my $type=pagetype($file);
my $page=$file;
$page=~s/\Q.$type\E*$// if defined $type && !$hooks{htmlize}{$type}{keepextension};
+ if ($config{indexpages} && $page=~/(.*)\/index$/) {
+ $page=$1;
+ }
return $page;
} #}}}
+sub newpagefile ($$) { #{{{
+ my $page=shift;
+ my $type=shift;
+
+ if (! $config{indexpages} || $page eq 'index') {
+ return $page.".".$type;
+ }
+ else {
+ return $page."/index.".$type;
+ }
+} #}}}
+
sub targetpage ($$) { #{{{
my $page=shift;
my $ext=shift;
- if (! $config{usedirs} || $page =~ /^index$/ ) {
+ if (! $config{usedirs} || $page eq 'index') {
return $page.".".$ext;
- } else {
+ }
+ else {
return $page."/index.".$ext;
}
} #}}}
diff --git a/IkiWiki/Plugin/aggregate.pm b/IkiWiki/Plugin/aggregate.pm
index c7bd1875a..26c5cc9ae 100644
--- a/IkiWiki/Plugin/aggregate.pm
+++ b/IkiWiki/Plugin/aggregate.pm
@@ -158,11 +158,11 @@ sub migrate_to_internal { #{{{
next if $data->{expired};
$config{aggregateinternal} = 0;
- my $oldname = pagefile($data->{page});
+ my $oldname = "$config{srcdir}/".htmlfn($data->{page});
my $oldoutput = $config{destdir}."/".IkiWiki::htmlpage($data->{page});
$config{aggregateinternal} = 1;
- my $newname = pagefile($data->{page});
+ my $newname = "$config{srcdir}/".htmlfn($data->{page});
debug "moving $oldname -> $newname";
if (-e $newname) {
@@ -364,13 +364,13 @@ sub garbage_collect () { #{{{
foreach my $guid (values %guids) {
# any guid whose feed is gone should be removed
if (! exists $feeds{$guid->{feed}}) {
- unlink pagefile($guid->{page})
+ unlink "$config{srcdir}/".htmlfn($guid->{page})
if exists $guid->{page};
delete $guids{$guid->{guid}};
}
# handle expired guids
elsif ($guid->{expired} && exists $guid->{page}) {
- unlink pagefile($guid->{page});
+ unlink "$config{srcdir}/".htmlfn($guid->{page});
delete $guid->{page};
delete $guid->{md5};
}
@@ -570,7 +570,7 @@ sub add_page (@) { #{{{
}
my $c="";
while (exists $IkiWiki::pagecase{lc $page.$c} ||
- -e pagefile($page.$c)) {
+ -e "$config{srcdir}/".htmlfn($page.$c)) {
$c++
}
@@ -581,7 +581,7 @@ sub add_page (@) { #{{{
$c="";
$page=$feed->{dir}."/item";
while (exists $IkiWiki::pagecase{lc $page.$c} ||
- -e pagefile($page.$c)) {
+ -e "$config{srcdir}/".htmlfn($page.$c)) {
$c++
}
}
@@ -621,7 +621,7 @@ sub add_page (@) { #{{{
if (defined $mtime && $mtime <= time) {
# Set the mtime, this lets the build process get the right
# creation time on record for the new page.
- utime $mtime, $mtime, pagefile($guid->{page});
+ utime $mtime, $mtime, "$config{srcdir}/".htmlfn($guid->{page});
# Store it in pagectime for expiry code to use also.
$IkiWiki::pagectime{$guid->{page}}=$mtime;
}
@@ -679,12 +679,6 @@ sub htmlabs ($$) { #{{{
return $ret;
} #}}}
-sub pagefile ($) { #{{{
- my $page=shift;
-
- return "$config{srcdir}/".htmlfn($page);
-} #}}}
-
sub htmlfn ($) { #{{{
return shift().".".($config{aggregateinternal} ? "_aggregated" : $config{htmlext});
} #}}}
diff --git a/IkiWiki/Plugin/autoindex.pm b/IkiWiki/Plugin/autoindex.pm
index 6ff06538f..a79a06314 100644
--- a/IkiWiki/Plugin/autoindex.pm
+++ b/IkiWiki/Plugin/autoindex.pm
@@ -21,7 +21,7 @@ sub getsetup () { #{{{
sub genindex ($) { #{{{
my $page=shift;
- my $file=$page.".".$config{default_pageext};
+ my $file=newpagefile($page, $config{default_pageext});
my $template=template("autoindex.tmpl");
$template->param(page => $page);
writefile($file, $config{srcdir}, $template->output);
diff --git a/IkiWiki/Plugin/editpage.pm b/IkiWiki/Plugin/editpage.pm
index 8ab02cabc..794548c6d 100644
--- a/IkiWiki/Plugin/editpage.pm
+++ b/IkiWiki/Plugin/editpage.pm
@@ -156,7 +156,7 @@ sub cgi_editpage ($$) { #{{{
$type=pagetype($pagesources{$from});
}
$type=$config{default_pageext} unless defined $type;
- $file=$page.".".$type;
+ $file=newpagefile($page, $type);
if (! $form->submitted) {
$form->field(name => "rcsinfo", value => "", force => 1);
}
@@ -230,8 +230,8 @@ sub cgi_editpage ($$) { #{{{
# Previewing may have created files on disk.
# Keep a list of these to be deleted later.
my %previews = map { $_ => 1 } @{$wikistate{editpage}{previews}};
- foreach my $file (@{$renderedfiles{$page}}) {
- $previews{$file}=1 unless $wasrendered{$file};
+ foreach my $f (@{$renderedfiles{$page}}) {
+ $previews{$f}=1 unless $wasrendered{$f};
}
@{$wikistate{editpage}{previews}} = keys %previews;
$renderedfiles{$page}=[keys %wasrendered];
diff --git a/IkiWiki/Plugin/rename.pm b/IkiWiki/Plugin/rename.pm
index 3ee457ff0..6c131487a 100644
--- a/IkiWiki/Plugin/rename.pm
+++ b/IkiWiki/Plugin/rename.pm
@@ -279,7 +279,7 @@ sub sessioncgi ($$) { #{{{
$type=$ext;
}
- $destfile.=".".$type;
+ $destfile=newpagefile($dest, $type);
}
push @torename, {
src => $src,
@@ -292,17 +292,21 @@ sub sessioncgi ($$) { #{{{
# See if any subpages need to be renamed.
if ($q->param("subpages") && $src ne $dest) {
foreach my $p (keys %pagesources) {
- if ($pagesources{$p}=~m/^\Q$src\E\//) {
- my $d=$pagesources{$p};
- $d=~s/^\Q$src\E\//$dest\//;
- push @torename, {
- src => $p,
- srcfile => $pagesources{$p},
- dest => pagename($d),
- destfile => $d,
- required => 0,
- };
- }
+ next unless $pagesources{$p}=~m/^\Q$src\E\//;
+ # If indexpages is enabled, the
+ # srcfile should not be confused
+ # with a subpage.
+ next if $pagesources{$p} eq $srcfile;
+
+ my $d=$pagesources{$p};
+ $d=~s/^\Q$src\E\//$dest\//;
+ push @torename, {
+ src => $p,
+ srcfile => $pagesources{$p},
+ dest => pagename($d),
+ destfile => $d,
+ required => 0,
+ };
}
}
diff --git a/debian/changelog b/debian/changelog
index d7cbf38b5..1320e4f41 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -25,6 +25,11 @@ ikiwiki (2.66) UNRELEASED; urgency=low
page, and is preserved across rebuilds.
* editpage: Be more aggressive (and less buggy) about cleaning up
temporary files rendered during page preview.
+ * Add an indexpages option, which causes foo/index.mdwn to be the source
+ for page foo when foo.mdwn doesn't exist. Also, when it's enabled,
+ creating a new page will save it to foo/index.mdwn by default.
+ Closes: #474611
+ (Sponsored by The TOVA Company.)
* httpauth: Document that ikiwiki.cgi has to be in a directory subject to
authentication. Closes: #500524
diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn
index 4e27d361d..1b78f5900 100644
--- a/doc/plugins/write.mdwn
+++ b/doc/plugins/write.mdwn
@@ -691,6 +691,12 @@ destination file, as registered by `will_render`.
If the third parameter is passed and is true, an absolute url will be
constructed instead of the default relative url.
+#### `newpagefile($$)`
+
+This can be called when creating a new page, to determine what filename
+to save the page to. It's passed a page name, and its type, and returns
+the name of the file to create, relative to the srcdir.
+
#### `targetpage($$)`
Passed a page and an extension, returns the filename that page will be
diff --git a/doc/todo/index.html_allowed.mdwn b/doc/todo/index.html_allowed.mdwn
index 13ed49211..f030f9eea 100644
--- a/doc/todo/index.html_allowed.mdwn
+++ b/doc/todo/index.html_allowed.mdwn
@@ -121,4 +121,6 @@ diff -ru ikiwiki-2.4/IkiWiki.pm ikiwiki/IkiWiki.pm
</pre>
-This just makes it so that all files named foo/index become pages called foo, which is the desired effect. I haven't tested everything so far, so be careful! But you can see it working at http://ikidev.betacantrips.com/one/ again, as before. --Ethan \ No newline at end of file
+This just makes it so that all files named foo/index become pages called foo, which is the desired effect. I haven't tested everything so far, so be careful! But you can see it working at http://ikidev.betacantrips.com/one/ again, as before. --Ethan
+
+[[done]], the indexpages setting enables this.