kaapiandcode / hugo-goa

Simple Minimalistic Theme for Hugo
https://kaapiandcode.github.io/hugo-goa-demo/
MIT License
264 stars 128 forks source link

[1.0.0] <$image.Permalink>: nil pointer #122

Closed p7kdev closed 7 months ago

p7kdev commented 8 months ago

Hi,

first of all, thank you very much for the great theme. But I currently have a problem. I can no longer build my site with the latest release (1.0.0).

Error: error building site: render: failed to render pages: render of "home" failed: "hugo/themes/goa/layouts/index.html:3:3": execute of template failed: template: index.html:3:3: executing "index.html" at <partial "avatar.html" .>: error calling partial: "hugo/themes/goa/layouts/partials/avatar.html:4:21": execute of template failed: template: partials/avatar.html:4:21: executing "partials/avatar.html" at <$image.Permalink>: nil pointer evaluating resource.Resource.Permalink

This part seems new (layouts/partials/avatar.html).

  {{ with .Site.Params.authorimage }}
  {{ $image := resources.Get (printf "images/%s" .) }}
  <img src="{{ $image.Permalink }}" alt="Author Image" class="img-fluid rounded-circle mx-auto d-block headshot">
  {{ end }}

I have defined the authorimage variable in hugo.toml

authorimage = "profile.webp"

but it is located in static/img (as mentioned in the docs).

Do I have to define anything in addition? Is this a bug?

Many thanks already!

Best regards, Paul

kaapiandcode commented 7 months ago

I wonder if I changed the images dir to 'images' from the earlier 'img' when making the slew of updates. Can you check if that would work? I'll update the documentation.

kaapiandcode commented 7 months ago

Sorry, it does seem like I broke backward compatibility. changing the folder name from img to images should fix your issue @p7kdev

kaapiandcode commented 7 months ago

Here you go. https://github.com/kaapiandcode/hugo-goa/commit/bc81702b824176832eef2d2ca585cc11e1ccacad.

That should fix it.

p7kdev commented 7 months ago

Thank you very much! I tried it out a bit.

I renamed the img folder to images but i still got the same error. With the latest commit (https://github.com/kaapiandcode/hugo-goa/commit/bc81702b824176832eef2d2ca585cc11e1ccacad) the error is gone but the image is also missing in the compiled site. That's because the $image variable is no longer defined but the part {{ resources.Get (printf "images/%s" .) }} is empty which is also the root of the problem. It doesn't really matter if the image is in img or images.

What works is

  {{ with .Site.Params.authorimage }}
  {{ $image := (printf "images/%s" .) }}
  <img src="{{ $image }}" alt="Author Image" class="img-fluid rounded-circle mx-auto d-block headshot">
  {{ end }}

Which basically means that the image is there and can be found. I just assume that the function resources.Get does not work quite as intended.

hugo version
hugo v0.122.0+extended linux/amd64 BuildDate=unknown
kaapiandcode commented 7 months ago

Thanks for your input @p7kdev. I'll revert back to the previous state and investigate.

kaapiandcode commented 7 months ago

Demo Video / Screen Recording: https://github.com/kaapiandcode/hugo-goa/assets/673924/3df82a91-e737-4b47-a208-05e3a0b01e75

I tried the latest version of this theme on my demo repo and it seems to work. What am I doing differently?

p7kdev commented 7 months ago

Thanks for the demo. Now I got it! It was the parent directory.

Previously the image had to be placed in static/img, but now apparently in assets/img (or assets/images). However, other files would probably have to remain in static (e.g. custom.css). Therefore, this was not found. I have now moved the image to assets/images. And now it works as expected!

The static folder is still given in the README ;-).

Thank you very much for your help!