Commit Diff
Commit:
6fde82294555a73a233d5c2c0851a636253ead51
From:
Omar Polo <op@omarpolo.com>
Date:
Fri Aug 26 20:15:10 2022 UTC
Message:
print a pagination before *and* after the listing suggested by Stefan. to do this, rework the way index pages are done. Instead of generating the first half and then appending the navigation and the footer, generate only the body and change how fixfiles works to prepend the heading. this dance with temporary index files is needed because we don't know how many pages there are until we've consumed all the input.
commit - 4d7b2baaeb5d8ca44873fffc775b8a195a35d03f
commit + 6fde82294555a73a233d5c2c0851a636253ead51
blob - 97c0fa7bfe425ac4ac395e488855f7b2652ddb16
blob + 77a1d23066b5f2d263ba5eeb7c20282683b68329
--- mkindex
+++ mkindex
@@ -6,8 +6,6 @@ use File::Copy;
use warnings;
use v5.32;
-use File::Copy;
-
use OpenBSD::Pledge;
use OpenBSD::Unveil;
@@ -37,26 +35,27 @@ sub nextfile {
my $path = pagename($page);
open($pfh, '>', $path)
or die "can't open $path: $!";
+}
- my $title = "Game of Trees Mail Archive";
- $title .= " | page $page" if $page != 0;
- initpage($pfh, $title);
+sub nav {
+ my ($pfh, $first, $last, $n) = @_;
+ my ($next, $prev) = (pagename($n+1), pagename($n-1));
- my $subtitle = $page != 0 ? "<p>Page $page</p>" : "";
+ say $pfh "<nav class='next-prev'>";
+ say $pfh "<a href='$first'>First</a>" if $n > 1;
+ say $pfh "<a href='$prev'>Prev</a>" if $n > 0;
+ say $pfh "<a href='$next'>Next</a>" if $n < $page;
+ say $pfh "<a href='$last'>Last</a>" if $n < $page - 1;
+ say $pfh "</nav>";
+}
- my $hdr = <<EOF;
-<header class='index-header'>
- <a href="https://gameoftrees.org" target="_blank">
- <img src='/got.png'
- srcset='/got.png, /got@2x.png 2x'
- alt='"GOT" where the "O" is a cute smiling sun.' />
- </a>
- <h1>Game of Trees Mail Archive</h1>
- $subtitle
-</header>
-<main>
-EOF
- say $pfh $hdr;
+sub copyfrom {
+ my ($path, $fh) = @_;
+
+ # there are probably faster ways to do this like File::Copy,
+ # but it bypasses the bufio cache...
+ open(my $pfh, '<', $path) or die "can't open $path: $!";
+ print $fh $_ while (<$pfh>);
}
sub fixfiles {
@@ -66,25 +65,39 @@ sub fixfiles {
for (my $i = 0; $i <= $page; $i++) {
my $path = pagename($i);
+ my $dest = "$outdir/$path";
- open(my $pfh, '>>', $path)
- or die "can't open $path for append: $!";
+ open(my $pfh, '>', $dest)
+ or die "can't open $dest for writing: $!";
- if ($page > 1) {
- my ($next, $prev) = (pagename($i+1), pagename($i-1));
+ my $title = "Game of Trees Mail Archive";
+ $title .= " | page $page" if $page != 0;
+ initpage($pfh, $title);
- say $pfh "<nav class='next-prev'><!-- $pfh -->";
- say $pfh "<a href='$first'>First</a>" if $i > 1;
- say $pfh "<a href='$prev'>Prev</a>" if $i > 0;
- say $pfh "<a href='$next'>Next</a>" if $i < $page;
- say $pfh "<a href='$last'>Last</a>" if $i < $page - 1;
- say $pfh "</nav>";
- }
+ my $subtitle = $page != 0 ? "<p>Page $page</p>" : "";
+ my $hdr = <<EOF;
+<header class='index-header'>
+ <a href="https://gameoftrees.org" target="_blank">
+ <img src='/got.png'
+ srcset='/got.png, /got@2x.png 2x'
+ alt='"GOT" where the "O" is a cute smiling sun.' />
+ </a>
+ <h1>Game of Trees Mail Archive</h1>
+ $subtitle
+</header>
+<main>
+EOF
+ say $pfh $hdr;
+
+ nav $pfh, $first, $last, $i if $page > 1;
+ copyfrom($path, $pfh);
+ nav $pfh, $first, $last, $i if $page > 1;
+
say $pfh "</main>";
+
endpage($pfh);
close($pfh);
- move $path, "$outdir/$path";
}
}
Omar Polo