1 7d6d378a 2022-08-24 op #!/usr/bin/env perl
3 7d6d378a 2022-08-24 op use open ":std", ":encoding(UTF-8)";
9 7d6d378a 2022-08-24 op my $outdir = $ENV{'OUTDIR'};
10 7d6d378a 2022-08-24 op die 'Set $OUTDIR' unless defined $outdir;
11 7d6d378a 2022-08-24 op mkdir $outdir;
15 7d6d378a 2022-08-24 op my $logo = <<EOF;
16 7d6d378a 2022-08-24 op <img srcset='/got-tiny.png, /got-tiny@2x.png 2x'
17 7d6d378a 2022-08-24 op src='/got-tiny.png'
18 7d6d378a 2022-08-24 op alt='"GOT", but the "O" is a cute, smiling sun' />
22 7d6d378a 2022-08-24 op my $str = shift;
23 7d6d378a 2022-08-24 op $str =~ s/&/\&/g;
24 7d6d378a 2022-08-24 op $str =~ s/</\</g;
25 7d6d378a 2022-08-24 op $str =~ s/>/\>/g;
29 7d6d378a 2022-08-24 op sub initpage {
30 7d6d378a 2022-08-24 op my ($fh, $title) = @_;
31 7d6d378a 2022-08-24 op open(my $hdr, '<', 'head.html')
32 7d6d378a 2022-08-24 op or die "can't open head.html: $!";
33 7d6d378a 2022-08-24 op while (<$hdr>) {
34 7d6d378a 2022-08-24 op s/TITLE/$title/;
40 7d6d378a 2022-08-24 op my $fh = shift;
41 7d6d378a 2022-08-24 op open(my $foot, '<', 'foot.html')
42 7d6d378a 2022-08-24 op or die "can't open foot.html: $!";
43 7d6d378a 2022-08-24 op print $fh $_ while <$foot>;
46 7d6d378a 2022-08-24 op sub nextthread {
47 7d6d378a 2022-08-24 op endthread() if defined($tfh);
48 7d6d378a 2022-08-24 op my ($mid, $subj) = @_;
49 7d6d378a 2022-08-24 op my $dest = "$outdir/thread/$mid.html";
50 7d6d378a 2022-08-24 op open($tfh, '>', $dest) or die "can't open $dest: $!";
51 7d6d378a 2022-08-24 op initpage($tfh, $subj);
53 7d6d378a 2022-08-24 op print $tfh "<header class='mail-header'>";
54 7d6d378a 2022-08-24 op print $tfh "<p>";
55 7d6d378a 2022-08-24 op print $tfh $logo;
56 7d6d378a 2022-08-24 op print $tfh "<a href='/'>‹ Back to the index</a>";
57 7d6d378a 2022-08-24 op print $tfh "</p>";
58 7d6d378a 2022-08-24 op print $tfh "<dl><dt>Thread:</dt><dd>$subj</dd>";
59 7d6d378a 2022-08-24 op print $tfh "</header>\n";
60 7d6d378a 2022-08-24 op print $tfh "<div class='thread'>\n";
63 7d6d378a 2022-08-24 op sub endthread {
64 7d6d378a 2022-08-24 op print $tfh "</div>\n";
65 7d6d378a 2022-08-24 op endpage($tfh);
69 7d6d378a 2022-08-24 op sub entry_raw {
70 7d6d378a 2022-08-24 op my ($fh, $mid, $level, $date, $from, $subj) = @_;
72 7d6d378a 2022-08-24 op my $class = "";
73 7d6d378a 2022-08-24 op $class = "reply indent-$level" unless $level == 0;
74 7d6d378a 2022-08-24 op print $fh "<div id='$mid' class='mail $class'>";
75 7d6d378a 2022-08-24 op print $fh "<p class='mail-meta'>";
76 7d6d378a 2022-08-24 op print $fh "<time>$date</time> ";
77 7d6d378a 2022-08-24 op print $fh "<span class='from'>$from</span>";
78 7d6d378a 2022-08-24 op print $fh "<span class='colon'>:</span>";
79 7d6d378a 2022-08-24 op if ($fh != $tfh && $level == 0) {
80 7d6d378a 2022-08-24 op print $fh " (<a href='/thread/$mid.html'>thread</a>)";
82 7d6d378a 2022-08-24 op print $fh "</p>";
83 7d6d378a 2022-08-24 op print $fh "<p class='subject'>";
84 7d6d378a 2022-08-24 op print $fh "<a href='/$mid.html'>$subj</a>";
85 7d6d378a 2022-08-24 op print $fh "</p>";
86 7d6d378a 2022-08-24 op print $fh "</div>\n";
90 7d6d378a 2022-08-24 op entry_raw(\*STDOUT, @_);
91 7d6d378a 2022-08-24 op entry_raw($tfh, @_);
94 7d6d378a 2022-08-24 op initpage(\*STDOUT, "Game of Trees Mail Archive");
96 7d6d378a 2022-08-24 op <header class='index-header'>
97 7d6d378a 2022-08-24 op <a href="https://gameoftrees.org" target="_blank">
98 7d6d378a 2022-08-24 op <img src='/got.png'
99 7d6d378a 2022-08-24 op srcset='/got.png, /got@2x.png 2x'
100 7d6d378a 2022-08-24 op alt='"GOT" where the "O" is a cute smiling sun.' />
102 7d6d378a 2022-08-24 op <h1>Game of Trees Mail Archive</h1>
107 7d6d378a 2022-08-24 op my $threads_seen = 0;
110 7d6d378a 2022-08-24 op m/^[^ ]+ <([^>]+)> (.+)(\d{4}-\d{2}-\d{2} \d{2}:\d{2}) <([^>]+)> (.*)/;
111 7d6d378a 2022-08-24 op die "woops; $_\n" unless defined $1;
113 7d6d378a 2022-08-24 op my ($mid, $indent, $date, $from, $subj) = ($1, $2, $3, $4, $5);
114 7d6d378a 2022-08-24 op $from =~ s/\s+$//;
115 7d6d378a 2022-08-24 op $from = san($from);
116 7d6d378a 2022-08-24 op $subj = san($subj);
118 7d6d378a 2022-08-24 op my $level = length($indent) - 1;
119 7d6d378a 2022-08-24 op $level = 10 if $indent =~ m/\.\.\d{2}\.\./;
121 7d6d378a 2022-08-24 op $mid =~ s,_,__,g;
122 7d6d378a 2022-08-24 op $mid =~ s,/,_,g;
124 7d6d378a 2022-08-24 op $subj =~ s/\s+/ /g;
125 7d6d378a 2022-08-24 op $subj =~ s/\s+$//g;
127 7d6d378a 2022-08-24 op my $new_thread = $indent eq " ";
128 7d6d378a 2022-08-24 op say "</section> <hr />" if $threads_seen && $new_thread;
129 7d6d378a 2022-08-24 op if ($new_thread) {
130 7d6d378a 2022-08-24 op nextthread($mid, $subj);
131 7d6d378a 2022-08-24 op say "<section class='thread'>";
134 7d6d378a 2022-08-24 op $threads_seen = 1;
136 7d6d378a 2022-08-24 op entry($mid, $level, $date, $from, $subj);
139 7d6d378a 2022-08-24 op if ($threads_seen) {
140 7d6d378a 2022-08-24 op say "</section>" ;
144 7d6d378a 2022-08-24 op say "</main>";
145 7d6d378a 2022-08-24 op endpage(\*STDOUT);