aboutsummaryrefslogtreecommitdiff
path: root/IkiWiki.pm
diff options
context:
space:
mode:
authorjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>2007-04-01 19:59:42 +0000
committerjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>2007-04-01 19:59:42 +0000
commit02b9f69ba5da59cca9ff198b731d63d643fff4db (patch)
tree12d42bdb28dae5c2e8ed5dc5a3a3e3ceb74df0a4 /IkiWiki.pm
parent1087e234f067fd888bff063563ee5c53ef038d82 (diff)
downloadikiwiki-02b9f69ba5da59cca9ff198b731d63d643fff4db.tar
ikiwiki-02b9f69ba5da59cca9ff198b731d63d643fff4db.tar.gz
* Finally apply the index.html patch, with thanks to everyone who worked
on and supported creating it (especially Tumov). This adds a "usedirs" option that makes ikiwiki use foo/index.html instead of foo.html as output page names. It is not yet enabled by default.
Diffstat (limited to 'IkiWiki.pm')
-rw-r--r--IkiWiki.pm48
1 files changed, 44 insertions, 4 deletions
diff --git a/IkiWiki.pm b/IkiWiki.pm
index 558b457f1..c272a294e 100644
--- a/IkiWiki.pm
+++ b/IkiWiki.pm
@@ -15,7 +15,7 @@ use vars qw{%config %links %oldlinks %pagemtime %pagectime %pagecase
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
+ displaytime will_render gettext urlto targetpage
%config %links %renderedfiles %pagesources);
our $VERSION = 1.02; # plugin interface version, next is ikiwiki version
our $version="1.45";my $installdir="/usr";
@@ -72,6 +72,7 @@ sub defaultconfig () { #{{{
sslcookie => 0,
httpauth => 0,
userdir => "",
+ usedirs => 0,
numbacklinks => 10,
} #}}}
@@ -224,10 +225,21 @@ sub pagename ($) { #{{{
return $page;
} #}}}
-sub htmlpage ($) { #{{{
+sub targetpage ($$) { #{{{
my $page=shift;
+ my $ext=shift;
+
+ if (! $config{usedirs} || $page =~ /^index$/ ) {
+ return $page.".".$ext;
+ } else {
+ return $page."/index.".$ext;
+ }
+} #}}}
- return $page.".html";
+sub htmlpage ($) { #{{{
+ my $page=shift;
+
+ return targetpage($page, "html");
} #}}}
sub srcfile ($) { #{{{
@@ -396,6 +408,7 @@ sub baseurl (;$) { #{{{
return "$config{url}/" if ! defined $page;
+ $page=htmlpage($page);
$page=~s/[^\/]+$//;
$page=~s/[^\/]+\//..\//g;
return $page;
@@ -425,6 +438,32 @@ sub displaytime ($) { #{{{
$config{timeformat}, localtime($time)));
} #}}}
+sub beautify_url ($) { #{{{
+ my $url=shift;
+
+ $url =~ s!/index.html$!/!;
+ $url =~ s!^$!./!; # Browsers don't like empty links...
+
+ return $url;
+} #}}}
+
+sub urlto ($$) { #{{{
+ my $to=shift;
+ my $from=shift;
+
+ if (! length $to) {
+ return beautify_url(baseurl($from));
+ }
+
+ if (! grep { $_ eq $to } map { @{$_} } values %renderedfiles) {
+ $to=htmlpage($to);
+ }
+
+ my $link = abs2rel($to, dirname(htmlpage($from)));
+
+ return beautify_url($link);
+} #}}}
+
sub htmllink ($$$;@) { #{{{
my $lpage=shift; # the page doing the linking
my $page=shift; # the page that will contain the link (different for inline)
@@ -464,7 +503,8 @@ sub htmllink ($$$;@) { #{{{
"\">?</a>$linktext</span>"
}
- $bestlink=abs2rel($bestlink, dirname($page));
+ $bestlink=abs2rel($bestlink, dirname(htmlpage($page)));
+ $bestlink=beautify_url($bestlink);
if (! $opts{noimageinline} && isinlinableimage($bestlink)) {
return "<img src=\"$bestlink\" alt=\"$linktext\" />";