From 82c2dce967453a0c3da56ec5cdd6697c6fbcac33 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 26 Aug 2024 22:33:23 +0300 Subject: add ToC suggester --- lib/template.source.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'lib/template.source.sh') diff --git a/lib/template.source.sh b/lib/template.source.sh index 88eba0f..626aed0 100644 --- a/lib/template.source.sh +++ b/lib/template.source.sh @@ -72,6 +72,19 @@ template::_line () { eval "${1/<< /}" } +# Sugesting adding a ToC when there are many sections +template::suggester::toc () { + find "$CONTENT_BASE_DIR/gemtext" -name \*.gmi | while read -r gmi_file; do + if $GREP -q '<< template::inline::toc' "$gmi_file"; then + continue # Has alread a ToC + fi + local -i num_sections="$($SED -E -n '/^```/,/^```/! { /^#+ /p; }' "$gmi_file" | wc -l)" + if [ $num_sections -ge 7 ]; then + echo "$gmi_file with $num_sections secions and no ToC - consider adding template::inline::toc!" + fi + done +} + # Can be used from a .gmi.tpl template for generating an index for a given topic. template::inline::index () { local topic='' -- cgit v1.2.3