]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki.pm
add padding between inlined page title and content
[ikiwiki.git] / IkiWiki.pm
index 9a81c7da4caaf635cfe111afa807ebea30401b76..82370f430ddd257544d47509ed4ffc0f14c5250f 100644 (file)
@@ -12,16 +12,16 @@ use Storable;
 use open qw{:utf8 :std};
 
 use vars qw{%config %links %oldlinks %pagemtime %pagectime %pagecase
-           %pagestate %renderedfiles %oldrenderedfiles %pagesources
-           %destsources %depends %hooks %forcerebuild $gettext_obj
-           %loaded_plugins};
+           %pagestate %wikistate %renderedfiles %oldrenderedfiles
+           %pagesources %destsources %depends %hooks %forcerebuild
+           $gettext_obj %loaded_plugins};
 
 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
-                 %config %links %pagestate %renderedfiles
+                add_underlay pagetitle titlepage linkpage newpagefile
+                 %config %links %pagestate %wikistate %renderedfiles
                  %pagesources %destsources);
 our $VERSION = 2.00; # plugin interface version, next is ikiwiki version
 our $version='unknown'; # VERSION_AUTOREPLACE done by Makefile, DNE
@@ -198,6 +198,13 @@ sub getsetup () { #{{{
                safe => 0, # changing requires manual transition
                rebuild => 1,
        },
+       indexpages => {
+               type => "boolean",
+               default => 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;
        }
 } #}}}
@@ -750,7 +773,7 @@ sub will_render ($$;$) { #{{{
 
        # Important security check.
        if (-e "$config{destdir}/$dest" && ! $config{rebuild} &&
-           ! grep { $_ eq $dest } (@{$renderedfiles{$page}}, @{$oldrenderedfiles{$page}})) {
+           ! grep { $_ eq $dest } (@{$renderedfiles{$page}}, @{$oldrenderedfiles{$page}}, @{$wikistate{editpage}{previews}})) {
                error("$config{destdir}/$dest independently created, not overwriting with version from $page");
        }
 
@@ -1318,9 +1341,11 @@ sub loadindex () { #{{{
        my $pages;
        if (exists $index->{version} && ! ref $index->{version}) {
                $pages=$index->{page};
+               %wikistate=%{$index->{state}};
        }
        else {
                $pages=$index;
+               %wikistate=();
        }
 
        foreach my $src (keys %$pages) {
@@ -1368,6 +1393,7 @@ sub saveindex () { #{{{
        my $newfile="$config{wikistatedir}/indexdb.new";
        my $cleanup = sub { unlink($newfile) };
        open (my $out, '>', $newfile) || error("cannot write to $newfile: $!", $cleanup);
+
        my %index;
        foreach my $page (keys %pagemtime) {
                next unless $pagemtime{$page};
@@ -1392,6 +1418,14 @@ sub saveindex () { #{{{
                        }
                }
        }
+
+       $index{state}={};
+       foreach my $id (@hookids) {
+               foreach my $key (keys %{$wikistate{$id}}) {
+                       $index{state}{$id}{$key}=$wikistate{$id}{$key};
+               }
+       }
+       
        $index{version}="3";
        my $ret=Storable::nstore_fd(\%index, $out);
        return if ! defined $ret || ! $ret;