github gohugoio/hugo v0.90.1

latest releases: v0.138.0, v0.137.1, v0.137.0...
2 years ago

This release contains some fixes and improvements related to error handling in remote lookups in resources.Get, as introduced in Hugo 0.90.0:

  • Now we will always return nil (never fail the build) when a resource is not found, also for remote resources (HTTP status code 404). This means that you can do {{ with $img }}{{ else }}{{/* insert a default image or something */}}{{ end }} and similar constructs, not having to consider where the resource source lives.
  • Fetching resources remotely over HTTPS has a much greater chance of failing (network down, server down) than reading a file from disk (if not already cached). And having this lead to a failing build is not always optimal. This release allows you to handle/ignore these errors in the templates if needed, see details below.

The return value from resources.Get now includes an .Err method that will be set if the call failed. If you want to just log any error as a WARNING you can use a construct similar to the one below.

{{ with resources.Get "https://gohugo.io/images/gohugoio-card-1.png" }}
  {{ with .Err }}
    {{ warnf "%s" . }}
  {{ else }}
    <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
  {{ end }}
{{ end }}

Note that if you do not handle .Err yourself, Hugo will fail the build the first time you start using the failed Resource object.

Changes

Don't miss a new hugo release

NewReleases is sending notifications on new releases.