aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile26
-rwxr-xr-xbin/mkdocs-prep.pl49
2 files changed, 60 insertions, 15 deletions
diff --git a/Makefile b/Makefile
index b20b315..5ea53f1 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-# Depends: myrepos git mkdocs w3c-linkchecker libtext-hogan-perl
+# Depends: myrepos git mkdocs w3c-linkchecker libconfig-tiny-perl libpath-tiny-perl libtext-hogan-perl
-include site.mk
@@ -10,14 +10,9 @@ gitshellhost ?= $(shellhost)
matrixhost ?= matrix.$(domain)
organisation ?= Example orga
contact_sysadmins ?= contact sysadmins
+VARIABLES = domain eventhost shellhost githost gitshellhost matrixhost organisation contact_sysadmins
-MUSTACHE = cat source/source/USE.md | perl -MText::Hogan::Compiler -0777 -nE '\
- my $$compiler = Text::Hogan::Compiler->new;\
- my $$template = $$compiler->compile($$_);\
- say $$template->render({ \
- domain => "$(domain)", eventhost => "$(eventhost)", shellhost => "$(shellhost)", githost => "$(githost)", gitshellhost => "$(gitshellhost)", \
- matrixhost => "$(matrixhost)", \
- organisation => "$(organisation)", contact_sysadmins => "$(contact_sysadmins)" })'
+MKDOCS_PREP ?= bin/mkdocs-prep.pl
all: doc
@@ -31,23 +26,24 @@ check:
docs:
mkdir -p docs
find docs -type l -delete
- $(MUSTACHE) < README.md > docs/index.md
- $(MUSTACHE) < SETUP.md > docs/setup.md
+ $(MKDOCS_PREP) README.md docs/index.md
+ $(MKDOCS_PREP) SETUP.md docs/setup.md
docs/%: source
mkdir -p docs/$*
- $(MUSTACHE) < source/$(subst /,-,$*)/README.md > docs/$*/index.md
+ $(MKDOCS_PREP) source/$(subst /,-,$*)/README.md docs/$*/index.md
$(if $(wildcard source/$(subst /,-,$*)/USE.md),\
- $(MUSTACHE) < source/$(subst /,-,$*)/USE.md > docs/$*/use.md)
+ $(MKDOCS_PREP) source/$(subst /,-,$*)/USE.md docs/$*/use.md)
$(if $(wildcard source/$(subst /,-,$*)/ADMIN.md),\
- $(MUSTACHE) < source/$(subst /,-,$*)/ADMIN.md > docs/$*/admin.md)
+ $(MKDOCS_PREP) source/$(subst /,-,$*)/ADMIN.md docs/$*/admin.md)
$(if $(wildcard source/$(subst /,-,$*)/SETUP.md),\
- $(MUSTACHE) < source/$(subst /,-,$*)/SETUP.md > docs/$*/setup.md)
+ $(MKDOCS_PREP) source/$(subst /,-,$*)/SETUP.md docs/$*/setup.md)
$(if $(wildcard source/$(subst /,-,$*)/DEVELOP.md),\
- $(MUSTACHE) < source/$(subst /,-,$*)/DEVELOP.md > docs/$*/devel.md)
+ $(MKDOCS_PREP) source/$(subst /,-,$*)/DEVELOP.md docs/$*/devel.md)
init:
mr update
+ $(if $(wildcard site.mk),,$(foreach v,$(VARIABLES),echo $v = $($v) >> site.mk;))
clean:
rm -rf site
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;