On my new site, the staging version of which is hosted on Cloudflare pages and whose repository is here, and using the method described in this page of the Hugo docs, Iβm trying to set up an image gallery in the following way:
1. css
.photos {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
grid-gap: 20px;
align-items: stretch;
}
.photos img {
border: 1px solid #ccc;
box-shadow: 2px 2px 6px 0px rgba(0, 0, 0, 0.3);
max-width: 100%;
}
2. data
2.1. tree
data
βββ photos
βββ archie-and-peggy
β βββ archie-at-three-weeks.json
βββ archie_and_peggy.json
βββ black-and-white
β βββ a-boy-in-a-south-madagascar-village.json
β βββ abandoned-ship-at-moynak.json
β βββ duck-collection-in-new-york-apartment.json
β βββ manhattan-skyline-from-brooklyn.json
β βββ masai-mara-national-reserve.json
β βββ pastries-in-patisserie-valerie.json
β βββ st-stephen-s-cathedral-in-vienna.json
β βββ statue-of-hermes-at-the-villa-medicis.json
β βββ the-burggarten-in-vienna.json
β βββ the-cloister-at-quattro-santi-coronati-rome.json
β βββ the-cloisters-at-new-college-oxford.json
β βββ the-fountain-at-place-du-grand-mezel-in-geneva.json
β βββ the-statue-of-st.-praxedes.json
β βββ traffic-at-tulear-madagascar.json
βββ black_and_white.json
βββ colour
β βββ a-village-in-south-madagascar.json
β βββ beduin-in-petra.json
β βββ bicycle-made-of-wire.json
β βββ children-in-south-madagascar-village.json
β βββ demonstration-for-animal-rights.json
β βββ driving-through-the-aral-sea.json
β βββ far-east-meets-near-east.json
β βββ kenyan-artifact.json
β βββ modelling-at-grand-palais.json
β βββ my-cat-peggy-aged-six-months.json
β βββ on-what-used-to-be-the-aral-sea.json
β βββ peggy-wanting-cuddles.json
β βββ soldiers-in-kiev.json
β βββ tents-in-the-karapakalstan-desert.json
β βββ the-chor-minor-at-bukhara.json
β βββ the-city-walls-at-khiva.json
β βββ the-new-building-at-magdalen-college.json
β βββ village-children-in-madagascar.json
βββ colour.json
βββ israel
β βββ a-bar-mitzvah-at-zion-gate.json
β βββ an-ice-cream-parlour-in-west-jerusalem.json
β βββ arab-women-playing-at-the-beach-tel-aviv.json
β βββ boys-playing-in-the-jewish-quarter.json
β βββ jews-praying-at-temple-mount.json
β βββ mohammedans-in-jerusalem.json
β βββ the-ethiopian-quarter-at-holy-sepulchre-church.json
β βββ the-margosa-hotel-in-jaffa.json
β βββ the-native-bazaar-near-the-holy-sepulchre.json
β βββ the-promised-land.json
β βββ two-worlds-collide-at-temple-mount.json
βββ israel.json
βββ me
βββ me.json
βββ paris
β βββ a-baker-in-rue-des-rosiers.json
β βββ a-marais-street-at-night.json
β βββ at-paris-photo-2017.json
β βββ eiffel-tower-from-mur-de-la-paix.json
β βββ french-tin-soldiers.json
β βββ gare-du-nord-paris-on-the-day-after-the-november-2015-shootings.json
β βββ montmartre-in-february.json
β βββ musee-du-jeu-de-paume.json
β βββ pont-alexandre-iii-paris-france.json
β βββ teddy-bear-in-a-paris-flat.json
β βββ the-anri-sala-exhibition-at-the-pompidou-centre.json
β βββ the-ile-de-la-cite-in-autumn.json
β βββ the-paris-zombie-march.json
β βββ the-paris-zombies.json
β βββ the-pompidou-centre-in-autumn.json
β βββ the-pompidou-centre-in-mid-winter.json
β βββ tricky-moment-in-rue-des-rosiers.json
β βββ tuileries-gardens-in-late-winter.json
βββ paris.json
2.2. .json file content
Iβm using two types of .json file:
2.2.1. a-boy-in-a-south-madagascar-village.json
There is one .json file for each image, stored in one the folders corresponding to a category that will then be rendered as a separate gallery. (At this stage, Iβm only using the id
part of the dataset, which contains the final component in the imageβs URL. The remainder will serve for a lightbox with a caption that Iβll add later.)
{
"alt": "A boy in a South Madagascar villager",
"caption": "Ampanihy is one of the poorest parts of Madagascar",
"id": "dadc7948-0dcb-4ad7-b614-bde264f9cc00",
"camera": "iPhone X back dual camera 4mm f/1.8",
"flickr": "52909011237",
"geolocation": {
"latitude": "25.009123",
"longitude": "44.126013"
}
}
2.2.2. black_and_white.json
In addition to the .json files for each image, thereβs also a .json file for each image folder, which includes a description and a Flickr album id to which I want to provide a link in due course.
{
"title": "Black and white",
"description": "Most of my favorite photographsβin keeping with my minimalist approach to art and to designβare black and white: these ones were shot all over the world.",
"flickr": "72157622017095408"
}
3. /content/_index.md
---
title: "Photos"
date: 2019-05-05T15:26:38+00:00
slug: "photos"
description: "Photographs by Donald Jenkins"
summary: "As Apple started producing increasingly seriously good cameras in their phones, I started using my [phone](https://www.flickr.com/photos/astorg/albums/72157621916056260) for the vast majority of my pictures. Many of the pictures on this page were taken with one. For serious pictures, have a look at [Flickr](https://www.flickr.com/photos/astorg), for more frequent updates, go to [Instagram](https://instagram.com/donaldjenkins_/). I tend to prefer working in black and white, but that isnβt by any means a systematic rule."
---
4. /layout/photos/section.html
{{ define "main" }}
<article class="archive">
<div id="content">
{{ .Summary }}
<div class="columns is-multiline">
<h2 id="black-and-white" class="title">Black and white</h2>
<p class="subtitle">{{ index .Site.Data.photos.black_and_white "description" | markdownify }}</p>
<div class="photos">
{{ range $.Site.Data.photos.black_and_white }}
{{ partial "widgets/gallery-image.html" . }}
{{ end }}
</div>
</div>
</div>
</article>
{{ end }}
My idea is that the <div>...</div>
section would then be repeated each of the sets of images in each of the subfolders in data/photos
(in this case, βcolourβ, βparisβ, βisraelβ, βarchie & peggyβ and βmeβ.
5. partials/widgets/gallery-image.html
{{ range .id }}
{{ $id := .id }}
{{ $image_url := printf "%s%s" .Site.Params.cloudflare_images $id }}
<img
src="{{ $image_url }}/w=420,gamma=0.36,quality=45"
alt=""
/>
{{ end }}
All images are stored in Cloudflare Images, with the URL being set as a parameter in config.toml
(as cloudflare_images
). The URL for the image is then concatenated by the partial for each of the .json files in the corresponding directory. By the way, I succeeded in setting up a similar workflow for my articles page.
Unfortunately, the above setup produces the following error:
Error: Error building site: failed to render pages: render of βsectionβ failed: β/Users/donaldjenkins/sites/donaldjenkins/layouts/photos/section.html:10:11β: execute of template failed: template: photos/section.html:10:11: executing βmainβ at <partial βwidgets/gallery-image.htmlβ .>: error calling partial: β/Users/donaldjenkins/sites/donaldjenkins/layouts/partials/widgets/gallery-image.html:1:11β: execute of template failed: template: partials/widgets/gallery-image.html:1:11: executing βpartials/widgets/gallery-image.htmlβ at <.id>: canβt evaluate field id in type string
Can anyone point to what Iβm getting wrong?