I have a specific use-case that doesn’t seem to be covered by the documentation. My page looks like this:
text
img img img img
text
img img img
text
img img img img img
etc.
So I need multiple rows of images, grouped in sets of 3-5, with multiple paragraphs of text in-between these sets of images.
Most of the responsive image examples I can find are either using the blog post featured image (one image only) or other images inside of a post or page which are assumed to be full-width, stretching all the way across the page.
In my case, I need each row of images to stretch evenly across the page, or at least stay within a certain width. Each image is a different size, both width and height.
Right now the images are full size and total around 35MB for just one page. I would like to make them responsive so that only minimal sizes are sent to the browser, but within the multiple row structure.
That’s not really about Hugo, it’s more about general HTML. But let me guide you in the right direction.
You need to use some kind of grid to have your three (or more) columns with the images in a row.
There are three ways you can achieve that, I’ll list them from easy to hardest:
Find out if your theme already includes a grid system.
You can find out looking at the CSS or to other pages that already have the sort of behavior you are looking for.
Implement something like the simple grid framework on your layout: https://simplegrid.io/
With that in place, and if you are using page bundles, you can just reference the img src as a relative path to display your images. To handle the images and resize using Hugo, you can place them all on an images directory of that page bundle with an inline shortcode to handle the resizing and optimization. (Personally, I prefer to handle each image one by one and keep a folder with hi-res versions.
I want to do responsive images via Hugo. I can set this up in pure HTML, but then I negate the benefits of markdown and really don’t need Hugo at all. I can use some javascript and just hand-code it all.
I have been experimenting with moving images into the content folders which makes them accessible as page bundles. I did originally get the images to display using img src as you mentioned, but each image was full-sized, went way off the right margin, and were not (obviously) resized/downsized. So I explored the use of srcset and sizes but was unable to get this to function.
I would much rather keep the inline code to a minimum and rely on external shortcodes or partials. Again, all of the examples of this I have found online were either referring to an image listed in the front matter, or just one image in the body, or an entire page of nothing but photos for a portfolio.
Currently exploring NetlifyCMS and Cloudinary as a possible help in this matter.
Actually I already had a basic grid layout set up by the time I read your response. I had major difficulties getting the markdown to parse (another thread) but it seems to be working now.
I do have all the hi-res images in the same folder with my page, so they are available for page bundle.
Unfortunately, after changing all code from straight markdown image links to the {{< img src= links I am getting a timeout error timed out initializing value. This is most likely a circular loop in a shortcode
@brunoamaral OK, thanks - that is a much more concise shortcode! Also, I wasn’t aware of a need to add a ‘resources’ section to the front matter. I think I see what you are doing here. Let me test.