diff --git a/README.md b/README.md index 67995ec..0fdb6b6 100644 --- a/README.md +++ b/README.md @@ -280,7 +280,9 @@ In the GeoJSON, `coordinates` are already in `[lon, lat]` order, the colour and | `alt` | yes | What the image shows. It is the thumbnail's alt text and the caption in the lightbox. | | `credit` | no | Photographer and licence, shown under the thumbnail and in the lightbox. | -Hugo crops the thumbnails to squares (keeping the most interesting part of the picture) at build time; the lightbox shows the original file. Without JavaScript, a thumbnail links to the original file. A missing image, a missing `alt` or a `gallery-image` outside a `gallery` stops the build with an error that names the page. +`{{< gallery ratio="original" >}}` keeps each image's own aspect ratio instead of cropping it to a square; a gallery with a single image then spans the full width, as on the home page. Without `ratio` (or with `ratio="square"`), the thumbnails are square. + +Hugo crops the square thumbnails (keeping the most interesting part of the picture) at build time; the lightbox shows the original file. Without JavaScript, a thumbnail links to the original file. A missing image, a missing `alt` or a `gallery-image` outside a `gallery` stops the build with an error that names the page. ## Shortcode: Event cards diff --git a/content/de/_index.md b/content/de/_index.md index 56e21d7..f3596e3 100644 --- a/content/de/_index.md +++ b/content/de/_index.md @@ -26,7 +26,9 @@ Hackertours-Desk: DECT 8687 "TOUR", +49 40 573 0830 8687 [C3Nav-Direktlink](https://40c3.c3nav.de/l/hackertours-desk/) Ihr findet uns im Foyer Eingang Mitte, neben den Kassen. - +{{< gallery ratio="original" >}} +{{< gallery-image src=`hackertours_banner_messe.jpg` alt=`Hackertours am Eingang Mitte der Messe und Congress Hamburg` credit=`CC0 Amzi` >}} +{{< /gallery >}} ## Veranstaltungen diff --git a/content/en/_index.md b/content/en/_index.md index 718c3f1..0a70edb 100644 --- a/content/en/_index.md +++ b/content/en/_index.md @@ -26,7 +26,9 @@ Hackertours Desk: DECT 8687 "TOUR", +49 40 573 0830 8687 [C3Nav Direct Link](https://40c3.c3nav.de/l/hackertours-desk/) You can find us at ground level of the Central Entrance foyer, next to the cash desk. - +{{< gallery ratio="original" >}} +{{< gallery-image src=`hackertours_banner_messe.jpg` alt=`Hackertours at Central Entrance of Messe und Congress Hamburg` credit=`CC0 Amzi` >}} +{{< /gallery >}} ## Events diff --git a/themes/hackertours/assets/css/_gallery.css b/themes/hackertours/assets/css/_gallery.css index 48534f5..6b61027 100644 --- a/themes/hackertours/assets/css/_gallery.css +++ b/themes/hackertours/assets/css/_gallery.css @@ -44,6 +44,17 @@ } } +/* ratio="original": the images keep their own shape, and a single one spans the full width. */ +.gallery--original { + .gallery__link img { + aspect-ratio: auto; + } + + .gallery__item:only-child { + grid-column: 1 / -1; + } +} + @media (prefers-reduced-motion: no-preference) { .gallery__link img { transition: scale 0.2s; diff --git a/themes/hackertours/layouts/_shortcodes/gallery-image.html b/themes/hackertours/layouts/_shortcodes/gallery-image.html index 89b88f3..026751e 100644 --- a/themes/hackertours/layouts/_shortcodes/gallery-image.html +++ b/themes/hackertours/layouts/_shortcodes/gallery-image.html @@ -19,17 +19,28 @@ One image in a gallery, see gallery.html. Params: {{- else if or (ne $image.ResourceType "image") (eq $image.MediaType.SubType "svg") -}} {{- errorf "gallery-image: %q is not a photo Hugo can resize: %s" $src .Position -}} {{- else -}} -{{- /* Square thumbnails at two sizes, never larger than the image itself. */ -}} +{{- /* Thumbnails at two sizes, never larger than the image itself: square, or uncropped with +ratio="original" on the gallery. */ -}} {{- /* Turned as its EXIF orientation says (phone photos are often stored sideways); browsers do that for the original, but Hugo doesn't when it resizes. */ -}} {{- $oriented := $image.Filter images.AutoOrient -}} -{{- $side := math.Min 800 $oriented.Width $oriented.Height | int -}} -{{- $small := $oriented.Fill (printf "%dx%d Smart" (div $side 2) (div $side 2)) -}} -{{- $large := $oriented.Fill (printf "%dx%d Smart" $side $side) -}} +{{- $small := "" -}} +{{- $large := "" -}} +{{- $sizes := "(min-width: 48rem) 34rem, 100vw" -}} +{{- if eq (.Parent.Get "ratio") "original" -}} + {{- $width := math.Min 1600 $oriented.Width | int -}} + {{- $small = $oriented.Resize (printf "%dx" (div $width 2)) -}} + {{- $large = $oriented.Resize (printf "%dx" $width) -}} + {{- $sizes = "(min-width: 48rem) 70rem, 100vw" -}} +{{- else -}} + {{- $side := math.Min 800 $oriented.Width $oriented.Height | int -}} + {{- $small = $oriented.Fill (printf "%dx%d Smart" (div $side 2) (div $side 2)) -}} + {{- $large = $oriented.Fill (printf "%dx%d Smart" $side $side) -}} +{{- end -}}