- my $pagelink="";
- my $path="";
- foreach my $dir (reverse split("/", $page)) {
- if (length($pagelink)) {
- $pagelink="<a href=\"$path$dir.html\">$dir</a>/ $pagelink";
- }
- else {
- $pagelink=$dir;
- }
- $path.="../";
- }
- $path=~s/\.\.\/$/index.html/;
- $pagelink="<a href=\"$path\">$wikiname</a>/ $pagelink";
-
- $content="<html>\n<head><title>$title</title></head>\n<body>\n".
- "<h1>$pagelink</h1>\n".
- $content.
- "</body>\n</html>\n";
-
- return $content;
-}
-
-sub render ($) {
- my $file=shift;
-
- my $type=pagetype($file);
- my $content=readpage($file);
- if ($type ne 'unknown') {
- my $page=pagename($file);
-
- $links{$page}=[findlinks($content)];
-
- $content=linkify($content, $file);
- $content=htmlize($type, $content);
- $content=linkbacks($content, $page);
- $content=finalize($content, $page);
-
- writepage(htmlpage($page), $content);
- $oldpagemtime{$page}=time;
- $renderedfiles{$page}=htmlpage($page);
- }
- else {
- $links{$file}=[];
- writepage($file, $content);
- $oldpagemtime{$file}=time;
- $renderedfiles{$file}=$file;
- }
-}
-
-sub loadindex () {
- open (IN, "$srcdir/.index") || return;
- while (<IN>) {
- ($_)=/(.*)/; # untaint
- chomp;
- my ($mtime, $file, $rendered, @links)=split(' ', $_);
- my $page=pagename($file);
- $pagesources{$page}=$file;
- $oldpagemtime{$page}=$mtime;
- $oldlinks{$page}=[@links];
- $links{$page}=[@links];
- $renderedfiles{$page}=$rendered;
- }
- close IN;
-}
-
-sub saveindex () {
- open (OUT, ">$srcdir/.index") || error("cannot write to .index: $!");
- foreach my $page (keys %oldpagemtime) {
- print OUT "$oldpagemtime{$page} $pagesources{$page} $renderedfiles{$page} ".
- join(" ", @{$links{$page}})."\n"
- if $oldpagemtime{$page};
- }
- close OUT;
-}
-
-sub prune ($) {
- my $file=shift;
-
- unlink($file);
- my $dir=dirname($file);
- while (rmdir($dir)) {
- $dir=dirname($dir);
- }
-}
-
-sub refresh () {
- # Find existing pages.
- my %exists;
- my @files;
- find({
- no_chdir => 1,
- wanted => sub {
- if (/\/\.svn\//) {
- $File::Find::prune=1;
- }
- elsif (! -d $_ && ! /\.html$/ && ! /\/\./) {
- my ($f)=/(^[-A-Za-z0-9_.:\/+]+$)/; # untaint
- if (! defined $f) {
- warn("skipping bad filename $_\n");
- }
- else {
- $f=~s/^\Q$srcdir\E\/?//;
- push @files, $f;
- $exists{pagename($f)}=1;
- }
- }
- },
- }, $srcdir);
-
- my %rendered;
-
- # check for added or removed pages
- my @add;
- foreach my $file (@files) {
- my $page=pagename($file);
- if (! $oldpagemtime{$page}) {
- debug("new page $page");
- push @add, $file;
- $links{$page}=[];
- $pagesources{$page}=$file;
- }