summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2023-03-24 12:13:47 +0200
committerPaul Buetow <paul@buetow.org>2023-03-24 12:13:47 +0200
commit9cdd770ac428eaef43af8bd5532f127df825999a (patch)
tree0dc9d1ad40f63a4a0b91385cdee3d36062cd41cf
parent57759ff94148a3329bcf651647734eed2a7751b4 (diff)
can specify multiple index topics for template::inline::index
-rw-r--r--README.md7
-rw-r--r--lib/template.source.sh27
2 files changed, 18 insertions, 16 deletions
diff --git a/README.md b/README.md
index 6aa4ceb..c0f6a79 100644
--- a/README.md
+++ b/README.md
@@ -150,17 +150,18 @@ Another thing you can do is to insert an index with links to similar blog posts.
```
See more entries about DTail:
-<< template::index dtail
+<< template::inline::index dtail golang
Blablabla...
```
-... scans all other post entries with `dtail` in the file name and generates a link list like this:
+... scans all other post entries with `dtail` and `golang` in the file name and generates a link list like this:
```
-See more entries about DTail:
+See more entries about DTail and Golang:
=> ./2022-10-30-installing-dtail-on-openbsd.gmi 2022-10-30 Installing DTail on OpenBSD
+=> ./2022-04-22-programming-golang.gmi 2022-04-22 The Golang Programming language
=> ./2022-03-06-the-release-of-dtail-4.0.0.gmi 2022-03-06 The release of DTail 4.0.0
=> ./2021-04-22-dtail-the-distributed-log-tail-program.gmi 2021-04-22 DTail - The distributed log tail program (You are currently reading this)
diff --git a/lib/template.source.sh b/lib/template.source.sh
index c4d054d..a8cc9ac 100644
--- a/lib/template.source.sh
+++ b/lib/template.source.sh
@@ -65,20 +65,21 @@ template::_line () {
}
# Can be used from a .gmi.tpl template for generating an index for a given topic.
-template::index () {
- local -r topic="$1"; shift
-
- while read -r gmi_file; do
- local date=$(cut -d- -f1,2,3 <<< "$gmi_file")
- local title=$($SED -n "/^# / { s/# //; p; q; }" "$gmi_file")
-
- local current=''
- if [ "$gmi_file" = "$CURRENT_GMI" ]; then
- current=" (You are currently reading this)"
- fi
+template::inline::index () {
+ local topic=''
+ for topic in "$@"; do
+ while read -r gmi_file; do
+ local date=$(cut -d- -f1,2,3 <<< "$gmi_file")
+ local title=$($SED -n "/^# / { s/# //; p; q; }" "$gmi_file")
+
+ local current=''
+ if [ "$gmi_file" = "$CURRENT_GMI" ]; then
+ current=" (You are currently reading this)"
+ fi
- echo "=> ./$gmi_file $date $title$current"
- done < <(ls | $GREP "$topic.*\\.gmi\$" | sort -r)
+ echo "=> ./$gmi_file $date $title$current"
+ done < <(ls | $GREP "$topic.*\\.gmi\$")
+ done | sort -r | uniq
}
template::test () {