From 40007b8111ff46d5bb7170296455116cd367dea0 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 29 Sep 2008 18:19:44 -0400 Subject: support indexpages when creating new pages Initial draft, may need to factor new page filename code out into helper function if other plugins need to do the same.. --- IkiWiki/Plugin/editpage.pm | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/editpage.pm b/IkiWiki/Plugin/editpage.pm index 8ab02cabc..f44e4f857 100644 --- a/IkiWiki/Plugin/editpage.pm +++ b/IkiWiki/Plugin/editpage.pm @@ -156,7 +156,12 @@ sub cgi_editpage ($$) { #{{{ $type=pagetype($pagesources{$from}); } $type=$config{default_pageext} unless defined $type; - $file=$page.".".$type; + if (! $config{indexpages}) { + $file=$page.".".$type; + } + else { + $file=$page."/index.".$type; + } if (! $form->submitted) { $form->field(name => "rcsinfo", value => "", force => 1); } @@ -230,8 +235,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]; -- cgit v1.2.3 From a7fd6debc50e95d189f08cd47d1fd1fe2a5aa2d6 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 29 Sep 2008 18:29:53 -0400 Subject: support indexpages when renaming pages Note that the page filename code used here and in editpage are identical.. --- IkiWiki/Plugin/rename.pm | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/rename.pm b/IkiWiki/Plugin/rename.pm index 3ee457ff0..b2c3eedfe 100644 --- a/IkiWiki/Plugin/rename.pm +++ b/IkiWiki/Plugin/rename.pm @@ -279,7 +279,12 @@ sub sessioncgi ($$) { #{{{ $type=$ext; } - $destfile.=".".$type; + if (! $config{indexpages}) { + $destfile.=".".$type; + } + else { + $destfile.="/index.".$type; + } } push @torename, { src => $src, -- cgit v1.2.3 From 2ba168ac8357ad76de246d656b3da15bc9c0e722 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 29 Sep 2008 18:52:42 -0400 Subject: use newpagefile --- IkiWiki/Plugin/editpage.pm | 7 +------ IkiWiki/Plugin/rename.pm | 7 +------ 2 files changed, 2 insertions(+), 12 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/editpage.pm b/IkiWiki/Plugin/editpage.pm index f44e4f857..794548c6d 100644 --- a/IkiWiki/Plugin/editpage.pm +++ b/IkiWiki/Plugin/editpage.pm @@ -156,12 +156,7 @@ sub cgi_editpage ($$) { #{{{ $type=pagetype($pagesources{$from}); } $type=$config{default_pageext} unless defined $type; - if (! $config{indexpages}) { - $file=$page.".".$type; - } - else { - $file=$page."/index.".$type; - } + $file=newpagefile($page, $type); if (! $form->submitted) { $form->field(name => "rcsinfo", value => "", force => 1); } diff --git a/IkiWiki/Plugin/rename.pm b/IkiWiki/Plugin/rename.pm index b2c3eedfe..218cab489 100644 --- a/IkiWiki/Plugin/rename.pm +++ b/IkiWiki/Plugin/rename.pm @@ -279,12 +279,7 @@ sub sessioncgi ($$) { #{{{ $type=$ext; } - if (! $config{indexpages}) { - $destfile.=".".$type; - } - else { - $destfile.="/index.".$type; - } + $destfile=newpagefile($dest, $type); } push @torename, { src => $src, -- cgit v1.2.3 From 121efb246fb30d499dac001f39904de9c445bd07 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 29 Sep 2008 18:56:24 -0400 Subject: Removed the pagefile function, which was confusingly close in name to newpagefile. Note that newpagefile is not used here (or in recentchanges) because the internal use pages they generate are transient and unlikely to benefit from being put each in their own subdir. --- IkiWiki/Plugin/aggregate.pm | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'IkiWiki/Plugin') 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}); } #}}} -- cgit v1.2.3 From 733171bf3f1084ac5c497543538ec68839153f6d Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 29 Sep 2008 19:08:12 -0400 Subject: support indexpages --- IkiWiki/Plugin/autoindex.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'IkiWiki/Plugin') 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); -- cgit v1.2.3 From 826af4600a4e413ca8ec7b6d56f0a1cdca0ad635 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 1 Oct 2008 14:43:28 -0400 Subject: fix subpage rename bug with indexpages If indexpages is enabled, then foo/index.mdwn will look like a subpage of foo, so an additional check is needed to avoid trying to rename it twice. --- IkiWiki/Plugin/rename.pm | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/rename.pm b/IkiWiki/Plugin/rename.pm index 218cab489..6c131487a 100644 --- a/IkiWiki/Plugin/rename.pm +++ b/IkiWiki/Plugin/rename.pm @@ -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, + }; } } -- cgit v1.2.3