summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xgemtexter2
-rw-r--r--lib/template.source.sh13
2 files changed, 15 insertions, 0 deletions
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=''