summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-02-02 10:46:20 +0200
committerPaul Buetow <paul@buetow.org>2025-02-02 10:46:20 +0200
commitbee6c6beafe33810e57be4670f4654f413e15190 (patch)
treeae5d38073e360145edb2e11839559a123f15cf8b
parent46dc7a63480834aafdcecb3cd4e846e6ce7d4320 (diff)
intro of rindex inline template
-rw-r--r--README.md2
-rw-r--r--lib/template.source.sh15
2 files changed, 15 insertions, 2 deletions
diff --git a/README.md b/README.md
index b4d378a..c7b237a 100644
--- a/README.md
+++ b/README.md
@@ -202,6 +202,8 @@ See more entries about DTail and Golang:
Blablabla...
```
+You can use `<< template::inline::rindex dtail golang` for reverse sorting index.
+
Table of contents generation can be done in any template file. Just add:
```
diff --git a/lib/template.source.sh b/lib/template.source.sh
index 7bd3f93..963b272 100644
--- a/lib/template.source.sh
+++ b/lib/template.source.sh
@@ -85,8 +85,9 @@ template::suggester::toc () {
done
}
+
# Can be used from a .gmi.tpl template for generating an index for a given topic.
-template::inline::index () {
+template::inline::_index () {
local topic=''
for topic in "$@"; do
while read -r gmi_file; do
@@ -100,7 +101,17 @@ template::inline::index () {
echo "=> ./$gmi_file $date $title$current"
done < <(ls | $GREP -i "$topic.*\\.gmi\$" | $GREP -v DRAFT)
- done | sort | uniq
+ done
+}
+
+# Can be used from a .gmi.tpl template for generating an index for a given topic.
+template::inline::index () {
+ template::inline::_index $@ | sort -r | uniq
+}
+
+# Same as index, but reverse order
+template::inline::rindex () {
+ template::inline::_index $@ | sort | uniq
}
# TODO: Write unit test.