Hey Guys, I’m hours in and I can’t seem to get image processing to work in my shortcode, All my errors revolve around getting the image, things like “nil pointer evaluating resource.Resource.Resize” or can’t be a string…
My main questions are what folder should the images for the blog posts be in? content/images, static/images, assert/images, from my understanding Image Processing doesn’t work from the static folder and I think my image fetching is wrong.
This is my shortcode:
{{< test src="image.jpg" alt="some image that never loads" >}} located in a markdown file at content/posts.
Some failed attempts:
{{- $image := resources.Get "/images/refractory-cement.jpg" -}}
{{ $image := $resource.Resize "600x" }}
<img src="{{$image.RelPermalink}}" alt="forget about the alt" />
Thanks pkollitsch so just to be sure (since the last few hours have driven me insane) where would your images be? and the shortcode param name is the images src name with file extension like image.jpg or with file location?
Pretty sure {{ $original := .Page.Resources.GetMatch (printf "%s*" (.Get "name") ) }} returned nil pointer for me last time so I’m thinking my images are in the wrong place.
@Ben_0 I have a couple of starter site repos with shortcodes for image processing. My understanding from the documentation is that Hugo image processing requires images to be in the same folders as the content “calling” them, so that’s how I have them set up in the starters. Maybe they will help you.
@bwintx we should come up with some canonical/best practice examples of doing these things … When I get some time … However, my lastest shot at something similar is this:
Note that for image resources that can be processed, the need to live either in a content bundle or inside /assets. But also note that you can mount any folder into /assets.
@bep Understood. As I note in the repos, what I did was shamelessly ripped off from others who had a better grasp than I of page bundles, Hugo image processing, etc. But duly noted, sir.
Check out my shortcode in one of the comments above. I somehow have it working on images in the static directory too.
I did compile that code from several blog posts quite a while back and used it without starting up my brain since … there might be something useful hidden inside.
Hmm. Interesting. According to docs as I understand them (which, I grant you, is a huge qualifier), that shouldn’t be possible. Assume you’re talking about a standard placement of the assets and static directories and their respective contents. (And, of course, note what @bep said above.)
@davidsneighbour Well, if you’d been able to make that happen from static, I think it’s safe to say you’d have a lot of people wanting to know how. Me among them.
I should delete all my posts as long as Google didn’t index my shameful false statements
I really need to start documenting my templates so I know whats going on some years after adding them.
Having used a number of SSGs, I can tell you there’s a ton of people in all of them who struggle to grasp how each handles assets like these. (As for me, despite those sample repos I mentioned, on my real site I’ve taken the easy way out and gone with Cloudinary. )