GoranStimac.com



GoHugo Release v0.95.0

Even faster, continue and break support, short-circuit of the built-in and/or-operators. This release upgrades to Go 1.18. This has made Hugo even faster. How much faster will depend on your site etc., but GoHugo team have benchmarks that show significant improvements. But the main reason GoHugo team and me are exited about this is the improvements in Go templates:

There are two new keywords, break and continue. These behaves like you would expect coming from other programming languages:

{{ range $i, $p := site.RegularPages }}
  {{ if gt $i 2 }}
    {{/* Break out of range, we only want to print the first 3 pages. */}}
    {{ break }}
  {{ end }}
  {{ $p.Title }}
{{ end }}
{{ range $i, $p := site.RegularPages }}
  {{ if eq $i 2 }}
    {{/* Skip the 3rd page. */}}
    {{ continue }}
  {{ end }}
  {{ $p.Title }}
{{ end }}

Also, the two built-in operators/function and and or now short-circuits, also in line with how && and || behave in other programming languages. This is useful in situations where the right side may have side effects (may be nil, is slow to execute etc.):

{{ if and .File (eq .File.Extension "html") }}
{{ end }}

Notes

  • Hugo now only builds with Go versions >= 1.18. Note that you do not need Go installed to run Hugo, and for Hugo Modules, any recent Go version can be used.

Changes

Related Posts