summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2023-03-24 11:41:08 +0200
committerPaul Buetow <paul@buetow.org>2023-03-24 11:41:08 +0200
commit57759ff94148a3329bcf651647734eed2a7751b4 (patch)
tree2eb06b4efef7ee483f1e1cb39899de918891a84d
parentd3298957aaabf0b01d3f7c092d2d4185af8f6871 (diff)
add template::index
-rw-r--r--README.md23
-rw-r--r--lib/template.source.sh21
2 files changed, 43 insertions, 1 deletions
diff --git a/README.md b/README.md
index ad8c310..6aa4ceb 100644
--- a/README.md
+++ b/README.md
@@ -145,6 +145,29 @@ Multiline template line 9
Multiline template line 10
```
+Another thing you can do is to insert an index with links to similar blog posts. E.g.:
+
+```
+See more entries about DTail:
+
+<< template::index dtail
+
+Blablabla...
+```
+
+... scans all other post entries with `dtail` in the file name and generates a link list like this:
+
+```
+See more entries about DTail:
+
+=> ./2022-10-30-installing-dtail-on-openbsd.gmi 2022-10-30 Installing DTail on OpenBSD
+=> ./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)
+
+Blablabla...
+```
+
+
### Alternative configuration file path
If you don't want to mess with `gemtexter.conf`, you can use an alternative config file path in `~/.config/gemtexter.conf`, which takes precedence if it exists. Another way is to set the `CONFIG_FILE_PATH` environment variable, e.g.:
diff --git a/lib/template.source.sh b/lib/template.source.sh
index c1487ba..c4d054d 100644
--- a/lib/template.source.sh
+++ b/lib/template.source.sh
@@ -21,10 +21,12 @@ template::_generate_file () {
local -r dest="${tpl/.tpl/}"
cd "$tpl_dir" || log PANIC "Unable to chdir to $tpl_dir"
- log INFO "$tpl_path -> $dest"
+ log INFO "Generating $tpl_path -> $dest"
+ export CURRENT_GMI="$dest" # Environt var can be used by .gmi.tpl
template::_generate < "$tpl" > "$dest.tmp"
mv "$dest.tmp" "$dest"
+ log INFO "Done generating $dest"
cd -
}
@@ -62,6 +64,23 @@ template::_line () {
eval "${1/<< /}"
}
+# 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
+
+ echo "=> ./$gmi_file $date $title$current"
+ done < <(ls | $GREP "$topic.*\\.gmi\$" | sort -r)
+}
+
template::test () {
assert::equals "$(template::_line '<< echo -n foo')" 'foo'
assert::equals "$(template::_line '<< echo foo')" 'foo'