summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-08-26 22:33:23 +0300
committerPaul Buetow <paul@buetow.org>2024-08-26 22:33:23 +0300
commit82c2dce967453a0c3da56ec5cdd6697c6fbcac33 (patch)
tree3dc04201ed3c1895ee20e39e1ec290e4d3dacffe /lib
parent2bd2e05538f77a1a82f5c2552da5eb4bce092c59 (diff)
add ToC suggester
Diffstat (limited to 'lib')
-rw-r--r--lib/template.source.sh13
1 files changed, 13 insertions, 0 deletions
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=''