aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2021-06-04 10:57:44 +0200
committerJonas Smedegaard <dr@jones.dk>2021-06-04 14:33:12 +0200
commit0518e8f506412510125eea8628572c13857673d0 (patch)
tree6a566abb53fa3501689bbd6a36865638af4e8c50 /bin
parent7adafdcf74f57254991b07f0fef62d9e36a6a1bc (diff)
externalize script bin/mkdocs-prep.pl, and (if missing) auto-generate site.mk in build target
Diffstat (limited to 'bin')
-rwxr-xr-xbin/mkdocs-prep.pl49
1 files changed, 49 insertions, 0 deletions
diff --git a/bin/mkdocs-prep.pl b/bin/mkdocs-prep.pl
new file mode 100755
index 0000000..e510185
--- /dev/null
+++ b/bin/mkdocs-prep.pl
@@ -0,0 +1,49 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use autodie;
+use List::Util qw(pairs);
+use Config::Tiny;
+use Path::Tiny;
+use Text::Hogan::Compiler;
+
+=head1 NAME
+
+mkdocs-prep - mkdocs preprocessor expanding mustache tokens
+
+=head1 VERSION
+
+Version 0.01
+
+=head1 SYNOPSIS
+
+=head1 DESCRIPTION
+
+B<mkdocs-prep> prepares a markdown document for B<mkdocs> processing.
+
+The document is treated as a mustache template
+and resolved using an external set of single-word tokens.
+
+Template tokens are gathered from external config file F<site.mk>,
+where each line lists a token, an equals sign, and replacement string.
+
+Each token in the document,
+wrapped with double curly brackets {{like_this}},
+is replaced (including brackets) with corresponding string.
+
+=cut
+
+my ( $infile, $outfile ) = @ARGV;
+
+my $config = Config::Tiny->new;
+$config = Config::Tiny->read( 'site.mk', 'utf8' );
+
+my $content = path($infile)->slurp_utf8;
+
+my $compiler = Text::Hogan::Compiler->new;
+my $template = $compiler->compile($content);
+
+path($outfile)->spew_utf8( $template->render( $config->{_} ) );
+
+1;