Template functions for semantic version comparisons

We already have a VersionString type that supports all of the above ops. I’m not sure if it’s fully semver compatible, but it’s what Hugo uses, so it’s … Hugo compatible. I think it’s exposed in a template somehow, but the main take is that we don’t want to re-implement all of the ne/ge/gt … in yet another API.

So instead of

{{ semver.Gt "v0.100.0" "v0.101.3" }} ---> false

You would do:

{{ gt (ver "v0.100.0")  ver("v0.101.3") }} ---> false

We certainly do some magic in other situations as well, so we could also maybe do

{{ gt "v0.100.0" "v0.101.3" }} ---> false

But that said, I’m not sure where this came from. We at least should have enough tools to determine if the current Hugo version is before/after a given string.

1 Like