Hugo 0.32 Related Questions/Discussions

A new thread to continue shortcode vs image etc. questions.

@RickCogley to get to the images from a shortcode:

range .Page.Resources ...


Thanks @bep.

I edited my config.toml per the guide:

Created this shortcode:

(css classes are from

Reference it like this:

 {{< figure imgname="kenpei-vespa_mandarinia_japonica-1" width="600x" type="Photo" title="Wikipedia Photo of Asian Giant Hornet" >}}

… in an in a folder I made from an existing post with an image:

The full size image is in the same folder as the, and, hugo server is rendering it fine locally, and I can see the image’s figure on the page.

When I try to deploy, I am getting:

Building sites … ERROR 2017/12/31 21:26:07 error processing shortcode "shortcodes/figure.html" for page "post/2017-09-02-Japan-PSA-Fall-is-Hornet-Season/": template: shortcodes/figure.html:6:18: executing "shortcodes/figure.html" at <$img.Resize>: error calling Resize: open /tmp/ no such file or directory

It is trying to resize the resized one. Somehow it is picking up the resized ones via the {{ $img := $.Page.Resources.GetByPrefix $imgname }} instead of my intent, which is to have it only resize the full size one in the post’s folder.

Maybe I have to re-do this to use range .Page.Resources ... as mentioned.

Edit - works on local like so:

OK, I think you found a bug … I admit I haven’t tested the resizing in shortcodes, just assumed it should just work, but it depends on the page and it’s resources being rendered first, which isn’t the case. Your site works if you build the site a second time (then the full size original is available).

I will need to think a little about a fix for this. As in: Not today.


Thanks @bep. This is what I am using to deploy to a standard linux:

hugodeploy-rcclive () {
	cd /path/to/RCC-live/
	rm -i -rf /tmp/
	chmod -R 775 /path/to/RCC-live/static/
	echo "Generating"
	hugo --config="/path/to/RCC-live/config.toml" --baseURL="" -s /path/to/RCC-live/ -d /tmp/
	echo "Syncing"
	/usr/local/bin/rsync -avz --delete --iconv=UTF-8-MAC,UTF-8 --exclude '.well-known' /tmp/ me@myhost.tdl:/path/to/webapps/rcclive1

I am removing the folder Hugo generates in this zsh function, so I commented the line that does that, and now, the second time works as you said.

# rm -i -rf /tmp/

(Haha, discourse puts a birthday cake next to one’s username on your birthday. )

1 Like

Happy Birthday @RickCogley :birthday:


Question about page bundling.

layouts/index.html: {{ len .Resources }}

Resources length is always zero. Doen’t matter how many image files i have in content.

It has to be a bundle. Which has a simple, but strict definition. Look in the docs.

Ok. I got it. It must be a separate directory with in it. Thanks.

But note that the home page can also be a bundle, but you need a “” content file in the root folder.

At the moment page resources and multihost localizations are not compatible: original/resized images are copied relative to the root of the docs folder, ignoring language subfolders (e.g. docs/en/ or docs/ru/).

Are there any plans to fix this issue?

You need to create an issue on GitHub for it to magically be fixed. I cannot fix something I don’t know about.
Hugo 0.32 was a massive release in more than one way, and there are bound to be issues I have not thought about. Please describe the issue in a GH issue.

Created issue:

1 Like

Is there a list of all the variables available in a resource element?
For now the HowTo article only mentions .ResourceType, .RelPermalink, .Permalink, .Width, .Height.
It would make sense to have the equivalent as for .File

For instance, I would need to retrieve the filename to exclude the “featured.jpg” image from a gallery.


1 Like

It can be a File, but the Image resource is not.

Ok got it.

I would just need to use readFile on it, but I wasn’t able to figure out how to get the path relative to my hugo project root folder as per readFile requirement. All I have is AbsSourceFilename

We may improve in this later, but if you want to exclude a file I suggest you just filter on the RelPermalink (use strings.Contains)

Yes will do that in the mean time!

Thanks a lot.

Why .Resources.ByType "page" and not .Resources.ByKind "page"?

Because that would not work. Just try it.