| git.druid.rocks | index | druid520 | kaboom | mk/ | gensummary.pl |
mk/gensummary.pl
#!/usr/bin/env perl
# regenerates docs/index.btft from docs/index.btft.in (the hand-edited
# template, tracked in git) by substituting the literal {{SUMMARY}}
# marker with docs/summary.txt's own one-line content -- mirrors mp's
# own mk/genconfdoc.pl pattern exactly: a single source of truth
# (summary.txt) instead of hand-editing the banner text and the
# generated page slowly drifting apart. run as part of "mk . d"/"sh
# mk/d.sh", same as every other doc-generation step; NEVER hand-edit
# docs/index.btft directly, edit docs/index.btft.in or docs/summary.txt
# and regenerate instead.
use v5.16;
use strict;
use warnings;
my $summary_file = 'docs/summary.txt';
my $template_file = 'docs/index.btft.in';
my $out_file = 'docs/index.btft';
open my $sfh, '<', $summary_file or die "err: cannot open $summary_file: $!\n";
my $summary = <$sfh>;
close $sfh;
chomp $summary if defined $summary;
$summary //= '';
open my $tfh, '<', $template_file or die "err: cannot open $template_file: $!\n";
local $/;
my $template = <$tfh>;
close $tfh;
my $count = ($template =~ s/\{\{SUMMARY\}\}/$summary/g);
die "err: $template_file has no {{SUMMARY}} marker.\n" unless $count;
open my $ofh, '>', $out_file or die "err: cannot write $out_file: $!\n";
print $ofh $template;
close $ofh;