And fail the build with an error for versions below the minimum version?
{{- $minHugoVersion := "0.114.0" }}
{{- if lt hugo.Version $minHugoVersion }}
{{- errorf "Something requires Hugo v%s or later." $minHugoVersion }}
{{- end }}
I forgot about…
hugo.toml
[module.hugoVersion]
extended = true
min = '0.113.0'
Which emits this warning in the console:
WARN 2023/06/09 17:35:20 Module "project" is not compatible with this Hugo version; run "hugo mod graph" for more information.
This worked. But can it be configured to fail the build rather than omit a warning?
If you need to fail the build, use the first option.
I placed the code at the top of the the baseof.html file and it generates the same error 3 times. Is that expected?
$ hugo server
Start building sites …
hugo v0.112.7-ea3c95a7b0f2140c248c1f40246a2e7acd2ada62+extended windows/amd64 BuildDate=2023-06-02T07:07:11Z VendorInfo=gohugoio
ERROR 2023/06/10 17:45:16 Only Hugo v0.113.0 or later is supported.
ERROR 2023/06/10 17:45:19 Only Hugo v0.113.0 or later is supported.
ERROR 2023/06/10 17:45:19 Only Hugo v0.113.0 or later is supported.
Built in 5212 ms
Error: error building site: logged 3 error(s)
Is this a multilingual site?
yes it is.
So run the code (a) only on the first site (language) and (b) only on the home page.
{{ if .Eq site.Sites.First.Home }}
{{- $minHugoVersion := "0.112.0" }}
{{- if lt hugo.Version $minHugoVersion }}
{{- errorf "Something requires Hugo v%s or later." $minHugoVersion }}
{{- end }}
{{ end }}
Thanks. Works now. Needed to use the code to fail the build on Cloudflare Pages to remind me (via email) to update the environment variable for Hugo version.