A new thread to continue shortcode vs image etc. questions.
@RickCogley to get to the images from a shortcode:
range .Page.Resources ...
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 tachyons.io)
Reference it like this:
{{< figure imgname="kenpei-vespa_mandarinia_japonica-1" width="600x" type="Photo" title="Wikipedia Photo of Asian Giant Hornet" >}}
… in an index.md
in a folder I made from an existing post with an image:
The full size image is in the same folder as the index.md
, 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:
Generating live.cogley.info
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/index.md": template: shortcodes/figure.html:6:18: executing "shortcodes/figure.html" at <$img.Resize>: error calling Resize: open /tmp/live.cogley.info/2017/09/02/japan-psa-fall-is-hornet-season/kenpei-vespa_mandarinia_japonica-1_hu8f527e1e41db4c1c1e613efc1f078c54_275471_600x0_resize_q80_box_center.jpg: 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/live.cogley.info
chmod -R 775 /path/to/RCC-live/static/
echo "Generating live.cogley.info"
hugo --config="/path/to/RCC-live/config.toml" --baseURL="http://live.cogley.info" -s /path/to/RCC-live/ -d /tmp/live.cogley.info
echo "Syncing live.cogley.info"
/usr/local/bin/rsync -avz --delete --iconv=UTF-8-MAC,UTF-8 --exclude '.well-known' /tmp/live.cogley.info/ 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/live.cogley.info
(Haha, discourse puts a birthday cake next to one’s username on your birthday. )
Happy Birthday @RickCogley
Question about page bundling.
layouts/index.html: {{ len .Resources }}
content/test.jpg
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 index.md/html in it. Thanks.
But note that the home page can also be a bundle, but you need a “_index.md” 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:
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.
Thanks
It can be a File
, but the Image
resource is not.
https://godoc.org/github.com/gohugoio/hugo/resource#Resource
https://godoc.org/github.com/gohugoio/hugo/resource#Image
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.