I’m currently trying to add a related content feature to my blog with thumbnails for each of the related posts.
What works like a charm:
Generating/getting related content
Generating thumbnails with the built-in image processing
Unfortunately I’m stuck though. how do I get the path to those thumbnails? I know the code which generates the unique filenames but afaik there’s no way to implement that in hugo templates, right?
Is there another way to add thumbnails to the related content without hard coding the paths in the front matter? Without thumbnails the related content is kinda useless in my case
Or to be more concrete: is there a way in hugo to get image hash, the second part following _hu?
I use page bundles for each post.
The first image resource per post will be used to generate a thumbnail.
So the thumbnail has a path like resources/_gen/images/blog/foobar/foo_hu5101bc7448d74c77047dbf0b923b0924_478402_500x500_fill_q60_box_smart1.jpeg
I’m able to re-construct the path with the help of the related post’s first resource’s .RelPermalink and os.Stat. The only dynamic part of the path which is missing is 5101bc7448d74c77047dbf0b923b0924 in the example above. Seems to be a (md5?) hash of the file content but (index .Resources 0).Content | md5 yields another hash.
I have post A and post B.
Below post A, I wanna show a thumbnail of post B with a link saying “See also:”.
But that’s just possible by accessing somehow the permalink of the automatically generated image. This permalink is no accessible outside the image operation’s scope though.
That’s the reason why I need to construct those filenames manually since there’s no other way to get the thumbnails’ permalinks. So my question is:
is there an official way to get the path of post B’s thumbnail in the scope of post A?
if not: what do I need to do to get the hash of the thumbnail’s filename?
Sure; also note that Hugo will effectively cache the processed image if you use the same resize operations on it in different templates (which is why I said that you would never be able to construct those URLs by hand – as those ops are encoded into the URL hash).