aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2021-06-04 14:21:24 +0200
committerJonas Smedegaard <dr@jones.dk>2021-06-04 14:34:52 +0200
commit22faacd38476f7af50cdafc5584baf8fb971a4bc (patch)
tree5148447ad2d96a2ed4ccef81d290cd683f02c125
parent1e8aebe4fee30c4c7e5c051581240f4857a8818f (diff)
prompt for strings for inline defined tokens not defined in site.mk; thanks to Siri Reiter for the idea
-rw-r--r--Makefile2
-rwxr-xr-xbin/mkdocs-prep.pl17
2 files changed, 18 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 5ea53f1..90ccc60 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-# Depends: myrepos git mkdocs w3c-linkchecker libconfig-tiny-perl libpath-tiny-perl libtext-hogan-perl
+# Depends: myrepos git mkdocs w3c-linkchecker libconfig-tiny-perl libpath-tiny-perl libtext-hogan-perl libio-prompter-perl
-include site.mk
diff --git a/bin/mkdocs-prep.pl b/bin/mkdocs-prep.pl
index efa71fb..96bba69 100755
--- a/bin/mkdocs-prep.pl
+++ b/bin/mkdocs-prep.pl
@@ -8,6 +8,7 @@ use List::Util qw(pairs);
use Config::Tiny;
use Path::Tiny;
use Text::Hogan::Compiler;
+use IO::Prompter;
=head1 NAME
@@ -35,6 +36,10 @@ wrapped with double curly brackets.
Template tokens are gathered from external config file F<site.mk>,
where each line lists a token, an equals sign, and replacement string.
+Inline defined tokens not declared in F<site.mk> will be prompted for.
+if a value is provided it will be used, and also saved in F<site.mk>.
+If no value is provided then inline default string is used.
+
Each token in the document,
wrapped with double curly brackets {{like_this}},
is replaced (including brackets) with corresponding string.
@@ -42,9 +47,11 @@ is replaced (including brackets) with corresponding string.
=cut
my ( $infile, $outfile ) = @ARGV;
+@ARGV = undef;
my $config = Config::Tiny->new;
$config = Config::Tiny->read( 'site.mk', 'utf8' );
+my $config_has_changed;
my $content = path($infile)->slurp_utf8;
@@ -55,6 +62,13 @@ while ( $section =~ /^(\w+)\h*:\h*(\w+(?:\h+\w+)*)/mg ) {
my $token = $1;
my $string = $2;
+ unless ( exists $config->{_}->{$1} ) {
+ $_ = prompt "Which string should replace token '$token'?";
+ next unless $_;
+ $config->{_}->{$1} = $_;
+ $config_has_changed++;
+ }
+
$content =~ s/\Q$string\E/{{$token}}/g;
};
@@ -64,4 +78,7 @@ my $template = $compiler->compile($content);
path($outfile)->spew_utf8( $template->render( $config->{_} ) );
+$config->write( 'site.mk', 'utf8' )
+ if $config_has_changed;
+
1;