diff --git a/ikiwiki b/ikiwiki index 7e4711059..2815a8e1d 100755 --- a/ikiwiki +++ b/ikiwiki @@ -5,6 +5,7 @@ use strict; use File::Find; use Memoize; use File::Spec; +use HTML::Template; BEGIN { $blosxom::version="is a proper perl module too much to ask?"; @@ -12,8 +13,8 @@ BEGIN { } $ENV{PATH}="/usr/local/bin:/usr/bin:/bin"; -my ($srcdir, $destdir, %links, %oldlinks, %oldpagemtime, %renderedfiles, - %pagesources); +my ($srcdir, $templatedir, $destdir, %links, %oldlinks, %oldpagemtime, + %renderedfiles, %pagesources); my $wiki_link_regexp=qr/\[\[([^\s]+)\]\]/; my $wiki_file_regexp=qr/(^[-A-Za-z0-9_.:\/+]+$)/; my $wiki_file_prune_regexp=qr!((^|/).svn/|\.\.|^\.|\/\.|\.html?$)!; @@ -27,7 +28,7 @@ my $historyurl=""; my $svn=1; sub usage { #{{{ - die "usage: ikiwiki [options] source dest\n"; + die "usage: ikiwiki [options] source templates dest\n"; } #}}} sub error ($) { #{{{ @@ -216,8 +217,7 @@ sub htmlize ($$) { #{{{ } } #}}} -sub linkbacks ($$) { #{{{ - my $content=shift; +sub backlinks ($) { #{{{ my $page=shift; my @links; @@ -235,13 +235,31 @@ sub linkbacks ($$) { #{{{ $p_trimmed=~s/^\Q$dir\E// && $page_trimmed=~s/^\Q$dir\E//; - push @links, "$p_trimmed"; + push @links, { url => $href, page => $p_trimmed }; } } - $content.="
Links: ".join(" ", sort @links)."
\n" if @links; - return $content; + return @links; } #}}} + +sub parentlinks ($) { + my $page=shift; + + my @ret; + my $pagelink=""; + my $path=""; + my $skip=1; + foreach my $dir (reverse split("/", $page)) { + if (! $skip) { + unshift @ret, { url => "$path$dir.html", page => $dir }; + } + else { + $skip=0; + } + $path.="../"; + } + return @ret; +} sub indexlink () { #{{{ return "$wikiname/ "; @@ -254,38 +272,30 @@ sub finalize ($$) { #{{{ my $title=basename($page); $title=~s/_/ /g; - my $pagelink=""; - my $path=""; - foreach my $dir (reverse split("/", $page)) { - if (length($pagelink)) { - $pagelink="$dir/ $pagelink"; - } - else { - $pagelink=$dir; - } - $path.="../"; - } - $path=~s/\.\.\/$/index.html/; - $pagelink=indexlink()." $pagelink"; + my $template=HTML::Template->new(blind_cache => 1, + filename => "$templatedir/page.tmpl"); - my @actions; if (length $cgiurl) { - push @actions, "Edit"; - push @actions, "RecentChanges"; + $template->param(editurl => "$cgiurl?do=edit&page=$page"); + $template->param(recentchangesurl => "$cgiurl?do=recentchanges"); } + if (length $historyurl) { - my $url=$historyurl; - $url=~s/\[\[\]\]/$pagesources{$page}/g; - push @actions, "History"; + my $u=$historyurl; + $u=~s/\[\[\]\]/$pagesources{$page}/g; + $template->param(historyurl => $u); } - $content="\n