aboutsummaryrefslogtreecommitdiff
path: root/bin/mkdocs-prep.pl
blob: e510185745acbc5182119edb60e78e6244f5c2b0 (plain)
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use autodie;
  5. use List::Util qw(pairs);
  6. use Config::Tiny;
  7. use Path::Tiny;
  8. use Text::Hogan::Compiler;
  9. =head1 NAME
  10. mkdocs-prep - mkdocs preprocessor expanding mustache tokens
  11. =head1 VERSION
  12. Version 0.01
  13. =head1 SYNOPSIS
  14. =head1 DESCRIPTION
  15. B<mkdocs-prep> prepares a markdown document for B<mkdocs> processing.
  16. The document is treated as a mustache template
  17. and resolved using an external set of single-word tokens.
  18. Template tokens are gathered from external config file F<site.mk>,
  19. where each line lists a token, an equals sign, and replacement string.
  20. Each token in the document,
  21. wrapped with double curly brackets {{like_this}},
  22. is replaced (including brackets) with corresponding string.
  23. =cut
  24. my ( $infile, $outfile ) = @ARGV;
  25. my $config = Config::Tiny->new;
  26. $config = Config::Tiny->read( 'site.mk', 'utf8' );
  27. my $content = path($infile)->slurp_utf8;
  28. my $compiler = Text::Hogan::Compiler->new;
  29. my $template = $compiler->compile($content);
  30. path($outfile)->spew_utf8( $template->render( $config->{_} ) );
  31. 1;