summaryrefslogtreecommitdiff
path: root/lib/template.source.sh
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-04-21 11:41:14 +0300
committerPaul Buetow <paul@buetow.org>2024-04-21 11:41:14 +0300
commit0377059719b0e7ceef084f6d5c42fe02cb01e2d2 (patch)
tree0b3c29cabe80cc0bd7eb5e0bb08d9af7f04ffb38 /lib/template.source.sh
parent754dda866799694e0365fde97387555d757ff0a4 (diff)
add TOC generator to the templating engine.
Diffstat (limited to 'lib/template.source.sh')
-rw-r--r--lib/template.source.sh13
1 files changed, 12 insertions, 1 deletions
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'