diff options
| author | Paul Buetow <paul@buetow.org> | 2026-04-26 19:22:29 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-04-26 19:22:29 +0300 |
| commit | 16b1ed918f4294302cf854c8041e1feb90da88bb (patch) | |
| tree | 984eaab47ef7c6e6f4b5f92088e6248153d3537a /lib | |
| parent | a38561d466f71bd5a683aa0c601e2331de3c3120 (diff) | |
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 <amp@ampcode.com>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/template.source.sh | 12 |
1 files changed, 11 insertions, 1 deletions
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' |
