summaryrefslogtreecommitdiff
path: root/lib/template.source.sh
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-16 09:16:38 +0300
committerPaul Buetow <paul@buetow.org>2026-05-16 09:16:38 +0300
commitd78949902946a58f440ad9145c94282c1512f3b1 (patch)
treed11214ca4428f61e9a60da2a7a43330a70cced1f /lib/template.source.sh
parentffcd91381f9d06c8c468cb06ce1793fe146d1e80 (diff)
Fix
Diffstat (limited to 'lib/template.source.sh')
-rw-r--r--lib/template.source.sh12
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/template.source.sh b/lib/template.source.sh
index 80d1fc8..86c5229 100644
--- a/lib/template.source.sh
+++ b/lib/template.source.sh
@@ -144,12 +144,20 @@ template::suggester::toc () {
# Can be used from a .gmi.tpl template for generating an index for a given topic.
+# Prefers reading the title from the .gmi.tpl source when present, because the
+# matching .gmi may be stale within a single --generate run: templates are
+# processed serially, so an index built early in the loop would otherwise pick
+# up old titles from .gmi files that have not been regenerated yet.
template::inline::_index () {
local topic=''
- for topic in "$@"; do
+ for topic in "$@"; do
while read -r gmi_file; do
local date=$(cut -d- -f1,2,3 <<< "$gmi_file")
- local title=$(generate::extract_title "$gmi_file")
+ local title_src="$gmi_file"
+ if [ -f "$gmi_file.tpl" ]; then
+ title_src="$gmi_file.tpl"
+ fi
+ local title=$(generate::extract_title "$title_src")
local current=''
if [ "$gmi_file" = "$CURRENT_GMI" ]; then