X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/effd000ff281f2187bf653b6e1c6aa0fc796c5f9..0abdb278ad76957a309e4fa9da436be73070c595:/source.plp diff --git a/source.plp b/source.plp index e645cd2..b10f38b 100644 --- a/source.plp +++ b/source.plp @@ -43,13 +43,18 @@ Html({ say ''; -if (not $source) { - print "

Source files

"; +if (not $source or -d $source) { + PLP_START { + print "

Source files

"; + }; + + if ($source and $source ne 'tools') { + Abort("Directory index not permitted", '403 source not allowed'); + } print "

Project code distributed under the AGPL. Please contribute back.

"; say '\n"; @@ -74,6 +79,17 @@ else { -r $source or Abort("Requested file not found", '404 source not found'); my $size = (stat $source)->[7]; + my $cachefile = "source/$source.html"; + if (-e $cachefile and (stat $cachefile)->[9] >= (stat $source)->[9]) { + say '
';
+		print ReadFile($cachefile);
+		say '
'; + exit; + } + -e or mkdir for $cachefile =~ s{[^/]+\z}{}r; # dirname + open my $cache, '>', $cachefile + or Alert("Could not save cache", "Opening $cachefile failed: $!");; + if (my $hl = eval { $size < 32_768 or die 'large files take too long to parse'; require Text::VimColor; @@ -89,6 +105,7 @@ else { Statement => 'strong', Error => 'em', Todo => 'em', + PreProc => 'strong', ); say '
';
@@ -110,6 +127,7 @@ else {
 
 			$line = qq(<$tag class="sy-\l$type">$line) if $tag;
 			print $line;
+			print {$cache} $line if $cache;
 		}
 		say '
'; }