bjorn.now
Björn Andersson
1 min read

Hugo’s resources.Get only finds files in assets/, not static/.

I kept my assets/resources in static/ and didn’t get why I always had to write /absolute/urls and use hope as a strategy, when I moved them into assets/ I could look up all my assets.

The below would fail because it couldn’t find the asset:

{{ with resources.Get "/author/bjorn.jpg" }}
  <img src="{{ .RelPermalink }}" alt="Björn Andersson">
{{ end }}

Hugo has global assets accessed through resources.Get which only looks up in assets/. Then page assets that you get through .Page.Resources.Get instead, which I haven’t used yet.

If you want to use both, then do like the figure shortcode and do it in an or:

{{- with or (.Page.Resources.Get $u.Path) 
            (resources.Get $u.Path) -}}
{{- $src = .RelPermalink -}}
{{- end -}}