commit 6fde82294555a73a233d5c2c0851a636253ead51 from: Omar Polo date: Fri Aug 26 20:15:10 2022 UTC 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 strict; 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 ? "

Page $page

" : ""; + say $pfh ""; +} - my $hdr = < - - "GOT" where the "O" is a cute smiling sun. - -

Game of Trees Mail Archive

- $subtitle - -
-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 ""; - } + my $subtitle = $page != 0 ? "

Page $page

" : ""; + my $hdr = < + + "GOT" where the "O" is a cute smiling sun. + +

Game of Trees Mail Archive

+ $subtitle + +
+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 "
"; + endpage($pfh); close($pfh); - move $path, "$outdir/$path"; } }