From 0377059719b0e7ceef084f6d5c42fe02cb01e2d2 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 21 Apr 2024 11:41:14 +0300 Subject: add TOC generator to the templating engine. --- lib/template.source.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'lib/template.source.sh') diff --git a/lib/template.source.sh b/lib/template.source.sh index 5a7f023..5d9e4c1 100644 --- a/lib/template.source.sh +++ b/lib/template.source.sh @@ -28,7 +28,10 @@ template::_generate_file () { cd "$tpl_dir" || log PANIC "Unable to chdir to $tpl_dir" log INFO "Generating $tpl_path -> $dest" - export CURRENT_GMI="$dest" # Environt var can be used by .gmi.tpl + # Environment variables can be used from .gmi.tpl files + export CURRENT_TPL="$tpl_path" + export CURRENT_GMI="$dest" + template::_generate < "$tpl" > "$dest.tmp" mv "$dest.tmp" "$dest" log INFO "Done generating $dest" @@ -87,6 +90,14 @@ template::inline::index () { done | sort | uniq } +# To generate a table of contents +template::inline::toc () { + echo '```' + echo 'Table of contents:' + $GREP '^#' "$(basename "$CURRENT_TPL")" | $SED 's/#/ /g; s/^ //;' + echo '```' +} + template::test () { assert::equals "$(template::_line '<< echo -n foo')" 'foo' assert::equals "$(template::_line '<< echo foo')" 'foo' -- cgit v1.2.3