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 --- gemtexter | 2 ++ lib/template.source.sh | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/gemtexter b/gemtexter index da7ba2c..828d448 100755 --- a/gemtexter +++ b/gemtexter @@ -153,9 +153,11 @@ main () { notes::generate & wait generate::fromgmi html md + template::suggester::toc ;; --template) template::generate + template::suggester::toc ;; --git) $0 --git-add 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