Commit Diff
Commit:
04eab9af0be7f907e48d5952f56ab0e7436110ab
Date:
Thu Aug 25 10:07:18 2022
UTC
Message:
move some common code in a module
--- /dev/null
+++ GotMArc.pm
@@ -0,0 +1,50 @@
+package GotMArc;
+use strict;
+use warnings;
+use v5.32;
+use Exporter;
+
+our @ISA = qw(Exporter);
+our @EXPORT_OK = qw($logo san initpage endpage);
+
+our $logo = <<'EOF';
+<a href="https://gameoftrees.org" target="_blank">
+ <img srcset='/got-tiny.png, /got-tiny@2x.png 2x'
+ src='/got-tiny.png'
+ width='64' height='39'
+ alt='"GOT", but the "O" is a cute, smiling sun' /></a>
+EOF
+
+sub san {
+ my $str = shift;
+ $str =~ s/&/\&/g;
+ $str =~ s/</\</g;
+ $str =~ s/>/\>/g;
+ return $str;
+}
+
+my $hdr = do {
+ local $/ = undef;
+ open my $fh, "<", "head.html"
+ or die "can't open head.html: $!";
+ <$fh>;
+};
+
+sub initpage {
+ my ($fh, $title) = @_;
+ say $fh $hdr =~ s/TITLE/$title/r;
+}
+
+my $foot = do {
+ local $/ = undef;
+ open my $fh, "<", "foot.html"
+ or die "can't open foot.html: $!";
+ <$fh>;
+};
+
+sub endpage {
+ my $fh = shift;
+ say $fh $foot;
+}
+
+1;
--- mexp
+++ mexp
@@ -6,40 +6,13 @@ my $outdir = $ENV{'OUTDIR'};
use warnings;
use v5.32;
+use lib ".";
+use GotMArc qw(san $logo initpage endpage);
+
my $outdir = $ENV{'OUTDIR'};
die 'Set $OUTDIR' unless defined $outdir;
mkdir $outdir;
-my $hdr = do {
- local $/ = undef;
- open my $fh, "<", "head.html"
- or die "can't open head.html: $!";
- <$fh>;
-};
-
-my $foot = do {
- local $/ = undef;
- open my $fh, "<", "foot.html"
- or die "can't open foot.html: $!";
- <$fh>;
-};
-
-my $logo = <<EOF;
-<a href="https://gameoftrees.org" target="_blank">
- <img srcset='/got-tiny.png, /got-tiny@2x.png 2x'
- src='/got-tiny.png'
- width='64' height='39'
- alt='"GOT", but the "O" is a cute, smiling sun' /></a>
-EOF
-
-sub san {
- my $str = shift;
- $str =~ s/&/\&/g;
- $str =~ s/</\</g;
- $str =~ s/>/\>/g;
- return $str;
-}
-
my $tid;
while (<>) {
chomp;
@@ -67,7 +40,7 @@ while (<>) {
open(my $fh, '>', "$dest") or die "can't open $dest: $!";
- say $fh $hdr =~ s/TITLE/$subj/r;
+ initpage $fh, $subj;
# prepare the parts listing file
$ENV{'MESSAGE_ID'} = $mid;
@@ -127,14 +100,12 @@ while (<>) {
}
say $fh "</ul>" if $part_seen;
- print $fh $foot;
+ endpage $fh;
close($text);
close($mshow);
close($parts);
close($fh);
-
- # exit(0);
}
unlink "parts.html";
--- mkindex
+++ mkindex
@@ -6,6 +6,9 @@ my $outdir = $ENV{'OUTDIR'};
use warnings;
use v5.32;
+use lib ".";
+use GotMArc qw($logo san initpage endpage);
+
my $outdir = $ENV{'OUTDIR'};
die 'Set $OUTDIR' unless defined $outdir;
mkdir $outdir;
@@ -18,39 +21,6 @@ my $logo = <<EOF;
my $entries = 0;
my $entries_per_page = 100;
-my $logo = <<EOF;
-<a href="https://gameoftrees.org" target="_blank">
- <img srcset='/got-tiny.png, /got-tiny@2x.png 2x'
- src='/got-tiny.png'
- width='64' height='39'
- alt='"GOT", but the "O" is a cute, smiling sun' /></a>
-EOF
-
-sub san {
- my $str = shift;
- $str =~ s/&/\&/g;
- $str =~ s/</\</g;
- $str =~ s/>/\>/g;
- return $str;
-}
-
-sub initpage {
- my ($fh, $title) = @_;
- open(my $hdr, '<', 'head.html')
- or die "can't open head.html: $!";
- while (<$hdr>) {
- s/TITLE/$title/;
- print $fh $_;
- }
-}
-
-sub endpage {
- my $fh = shift;
- open(my $foot, '<', 'foot.html')
- or die "can't open foot.html: $!";
- print $fh $_ while <$foot>;
-}
-
sub pagename {
my $i = shift;
return $i == 0 && "index.html" || "$i.html";
Omar Polo