aboutsummaryrefslogtreecommitdiff
path: root/gen.pl
diff options
context:
space:
mode:
Diffstat (limited to 'gen.pl')
-rw-r--r--gen.pl62
1 files changed, 62 insertions, 0 deletions
diff --git a/gen.pl b/gen.pl
new file mode 100644
index 0000000..0b682c2
--- /dev/null
+++ b/gen.pl
@@ -0,0 +1,62 @@
+#!/usr/bin/perl
+
+# gen.pl -- generate static files for perlisdead.org
+
+use strict;
+use warnings;
+use experimental 'switch';
+use File::Copy;
+use FindBin '$Bin';
+
+# Change directory to script path
+chdir $Bin;
+
+# Generate index.html
+mkdir 'out' if ! -d 'out';
+open my $f, '<', 'src/index.html' or die "Could not open < src/index.html: $!";
+open my $g, '>', 'out/index.html.tmp' or die "Could not open > out/index.html.tmp: $!";
+for (<$f>) {
+ when (/^\.inc (.*)/) {
+ open my $h, '<', "inc/$1" or do {
+ warn "Could not open inc/$1: $!";
+ next;
+ };
+ print $g $_ while <$h>;
+ close $h;
+ }
+ when (/^\.eval (.*)/) {
+ no strict; no warnings; no experimental;
+ local *STDOUT = $g;
+ eval $1;
+ warn $@ if $@;
+ }
+ when (/^\.run (.*)/) {
+ open my $h, '<', "run/$1" or do {
+ warn "Could not open run/$1: $!";
+ next;
+ };
+ my $c = do { local $/; <$h> };
+ close $h;
+ local *STDOUT = $g;
+ local $0 = "run/$1";
+ no strict; no warnings; no experimental;
+ eval $c;
+ warn $@ if $@;
+ # I guess you could just shell out instead...
+ }
+ default {
+ print $g $_;
+ }
+}
+close $g;
+close $f;
+
+# Copy static files
+opendir my $dh, 'src' or die "Could not open directory src: $!";
+while (readdir $dh) {
+ copy "src/$_" => "out/$_" unless /^\./ or /^index\.html$/;
+}
+closedir $dh;
+
+# Rename temporary file
+move 'out/index.html.tmp' => 'out/index.html';