Best practice to check if Hugo feature is available in current version

hey there!

I’m looking for best practices when checking for a Hugo feature existence.
For exemple .Resources has been introduced in .32 but .Resources.Match in .34

For many CI host out there, you can choose your version of Hugo.
I really want to test drive which for some reason won’t let you use the most recent version of Hugo, (they’re stuck at 31.1, soon .32) even if you only need them to commit to your repo and not build/deploy…

Si I have to make sure, my code can use the latest Hugo features on Netlify but stay away from them in Forestry.

I could play around with isset and nested conditions, but I’d rather not push/deploy too much on the repo waiting for Forestry to give me a green badge…

Thanks for your help!

This doesn’t answer your question directly… but:

Couldn’t you just wget or curl the latest hugo from Releases and directly use that? I do something like that (actually use my latest DEV build of hugo) on Netlify.

Thanks but you’re right, it doesn’t solve my problem, I’m not even passing a build command to Forestry, for my config is just “commit to repo”…

I meant to say that see if Forestry has a way to specify the build command like Netlify.

Best practice is to read the release notes.

That is if you can choose the version. I’m talking about cases where you can’t. Like building a theme for exemple or working with CI imposing its own version like Forestry.

By the way I couldn’t find a way to check the .Resources object is available or if the .Resources.GetMatch method is available.

Best practice is to read the release notes.

Isn’t this about writing hugo templates with fallbacks, if a feature is not available?
E.g. a theme author does not know which hugo version a project uses.
There is

min_version    = "0.30.2"

in theme.toml

but this is only for published themes… EDIT: theme.toml is for any theme - see @bep’s answer below

the current version of the Hugo binary you are using

Maybe in addition something like:

.Hugo.hasFeature "foo"

true if feature foo is available, else false


.Hugo.hasFeature ".Resources.Match"

Would that make sense?

Lol I didn’t know this one! Thanks. I’ll use that in the mean time.

Hugo.hasFeature would it may be quiet complicated to implement.

Anyway, thanks for the Version tip!

No, the min_version is for any theme.

A theme does not have to define a theme.toml, but is encouraged to do so.

So if you try to run a theme with min_version = “0.30.2” on Hugo 0.29 you will get an ERROR.

1 Like

I understand all this. But it means building a theme for a certain version of Hugo and getting stuck with it if you don’t want to break your users current theme.

You can’t suddenly bump your min_version without risk.

Never the less the .Hugo.Version check is quiet enough for now I suppose.