From a9d7c5453ae0f214f86043381310b81ad358b933 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 29 Sep 2008 17:30:30 -0400 Subject: Add indexpages option This is the easy part of supporting foo/index.mdwn sources for page foo. Note that if foo.mdwn exists too, there will be a warning about multiple sources for the same page, and which is used is indeterminate. indexpages should also cause web based editing to create index source pages by default; this and other fallout of the option not yet implemented. --- IkiWiki.pm | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'IkiWiki.pm') diff --git a/IkiWiki.pm b/IkiWiki.pm index 9b7baa0ee..c01c59ac6 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -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,6 +626,9 @@ 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; } #}}} -- cgit v1.2.3 From 2d45a303e253c4a20ce456a82e8ac694b49c2c2d Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 29 Sep 2008 18:51:16 -0400 Subject: add newpagefile function --- IkiWiki.pm | 19 ++++++++++++++++--- doc/plugins/write.mdwn | 6 ++++++ 2 files changed, 22 insertions(+), 3 deletions(-) (limited to 'IkiWiki.pm') diff --git a/IkiWiki.pm b/IkiWiki.pm index c01c59ac6..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 @@ -632,13 +632,26 @@ sub pagename ($) { #{{{ 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/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 -- cgit v1.2.3