From 16b1ed918f4294302cf854c8041e1feb90da88bb Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 26 Apr 2026 19:22:29 +0300 Subject: Add template::dynamic directive for always-regenerate templates Templates that fetch data from external sources (e.g. via curl) need to bypass the mtime-based freshness check. Adding << template::dynamic to a .gmi.tpl file marks it for regeneration on every run without affecting the generated output. Amp-Thread-ID: https://ampcode.com/threads/T-019dca93-8625-7134-bd59-8fc52e3a4b9c Co-authored-by: Amp --- lib/template.source.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/template.source.sh b/lib/template.source.sh index 0e34a87..80d1fc8 100644 --- a/lib/template.source.sh +++ b/lib/template.source.sh @@ -51,8 +51,14 @@ template::_generate_file () { local -r tpl="$(basename "$tpl_path")" local -r dest="${tpl/.tpl/}" + # Templates containing template::dynamic are always regenerated (e.g. they + # fetch data from external sources whose freshness cannot be determined by + # file mtime alone). + local -i is_dynamic=0 + $GREP -q 'template::dynamic' "$tpl_path" && is_dynamic=1 + # Skip if output is newer than the template and all relevant siblings - if [[ "$FORCE_REBUILD" != yes ]] && [[ -f "$tpl_dir/$dest" ]]; then + if (( ! is_dynamic )) && [[ "$FORCE_REBUILD" != yes ]] && [[ -f "$tpl_dir/$dest" ]]; then local -r dest_mtime=$(stat -c '%Y' "$tpl_dir/$dest") local -r dir_newest=$(template::_dir_newest_mtime "$tpl_dir") if (( dest_mtime >= dir_newest )); then @@ -182,6 +188,10 @@ template::inline::toc () { ' } +template::dynamic () { + : +} + template::test () { assert::equals "$(template::_line '<< echo -n foo')" 'foo' assert::equals "$(template::_line '<< echo foo')" 'foo' -- cgit v1.2.3