Gallery: optional caption, with the credit appended; caption the home page photo
This commit is contained in:
parent
11712cd501
commit
3176e02889
6 changed files with 30 additions and 15 deletions
|
|
@ -265,7 +265,7 @@ In the GeoJSON, `coordinates` are already in `[lon, lat]` order, the colour and
|
||||||
|
|
||||||
## Shortcode: Image gallery
|
## Shortcode: Image gallery
|
||||||
|
|
||||||
`{{< gallery >}}` shows a page's photos as square thumbnails, two per row on wide screens and one per row on narrow ones. Clicking a thumbnail opens the full image in a lightbox with its alt text and credit; with more than one image, arrows (on screen, the arrow keys, or swiping) move between them, and Escape, the close button or a click beside the image closes it.
|
`{{< gallery >}}` shows a page's photos as square thumbnails, two per row on wide screens and one per row on narrow ones. Clicking a thumbnail opens the full image in a lightbox with its caption (or alt text) and credit; with more than one image, arrows (on screen, the arrow keys, or swiping) move between them, and Escape, the close button or a click beside the image closes it.
|
||||||
|
|
||||||
```markdown
|
```markdown
|
||||||
{{< gallery >}}
|
{{< gallery >}}
|
||||||
|
|
@ -277,8 +277,9 @@ In the GeoJSON, `coordinates` are already in `[lon, lat]` order, the colour and
|
||||||
| Param | Required | Content |
|
| Param | Required | Content |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| `src` | yes | The image: a file in the page's folder, or a path in `themes/hackertours/assets/`. It must be a photo Hugo can resize (JPEG, PNG, WebP…), not SVG. |
|
| `src` | yes | The image: a file in the page's folder, or a path in `themes/hackertours/assets/`. It must be a photo Hugo can resize (JPEG, PNG, WebP…), not SVG. |
|
||||||
| `alt` | yes | What the image shows. It is the thumbnail's alt text and the caption in the lightbox. |
|
| `alt` | yes | What the image shows, for people who can't see it. It names the thumbnail's link, so it can't be empty, and is shown in the lightbox when there is no caption. |
|
||||||
| `credit` | no | Photographer and licence, shown under the thumbnail and in the lightbox. |
|
| `caption` | no | Context for everyone, shown under the thumbnail and in the lightbox. Say something the alt text doesn't: screen readers read both, so the same text would be heard twice. |
|
||||||
|
| `credit` | no | Photographer and licence, appended to the caption under the thumbnail and in the lightbox. |
|
||||||
|
|
||||||
`{{< 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.
|
`{{< 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.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ 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.
|
[C3Nav-Direktlink](https://40c3.c3nav.de/l/hackertours-desk/) Ihr findet uns im Foyer Eingang Mitte, neben den Kassen.
|
||||||
|
|
||||||
{{< gallery ratio="original" >}}
|
{{< gallery ratio="original" >}}
|
||||||
{{< gallery-image src=`hackertours_banner_messe.jpg` alt=`Hackertours am Eingang Mitte der Messe und Congress Hamburg` credit=`CC0 Amzi` >}}
|
{{< gallery-image src=`hackertours_banner_messe.jpg` alt=`Glasfassade mit dem Schriftzug „Hamburg Messe + Congress, Eingang Mitte“ und dem Hackertours-Haltestellen-Schild` caption=`Hackertours am Eingang Mitte der Messe und Congress Hamburg` credit=`CC0 Amzi` >}}
|
||||||
{{< /gallery >}}
|
{{< /gallery >}}
|
||||||
|
|
||||||
## Veranstaltungen
|
## Veranstaltungen
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ 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.
|
[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 ratio="original" >}}
|
||||||
{{< gallery-image src=`hackertours_banner_messe.jpg` alt=`Hackertours at Central Entrance of Messe und Congress Hamburg` credit=`CC0 Amzi` >}}
|
{{< gallery-image src=`hackertours_banner_messe.jpg` alt=`Glass façade with the sign 'Hamburg Messe + Congress, Eingang Mitte' and a yellow HHA bus stop sign` caption=`Hackertours at Central Entrance of Messe und Congress Hamburg` credit=`CC0 Amzi` >}}
|
||||||
{{< /gallery >}}
|
{{< /gallery >}}
|
||||||
|
|
||||||
## Events
|
## Events
|
||||||
|
|
|
||||||
|
|
@ -65,9 +65,13 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.gallery__credit {
|
.gallery__caption {
|
||||||
margin-block-start: 0.25rem;
|
margin-block-start: 0.25rem;
|
||||||
font-family: var(--ff-alt);
|
font-family: var(--ff-alt);
|
||||||
|
font-size: var(--fs-s);
|
||||||
|
}
|
||||||
|
|
||||||
|
.gallery__credit {
|
||||||
font-size: var(--fs-xs);
|
font-size: var(--fs-xs);
|
||||||
color: var(--color-text-meta);
|
color: var(--color-text-meta);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
<figure class="lightbox__figure">
|
<figure class="lightbox__figure">
|
||||||
<img class="lightbox__image" alt="">
|
<img class="lightbox__image" alt="">
|
||||||
<figcaption class="lightbox__caption" aria-live="polite">
|
<figcaption class="lightbox__caption" aria-live="polite">
|
||||||
<span class="lightbox__alt"></span>
|
<span class="lightbox__text"></span>
|
||||||
<span class="lightbox__credit"></span>
|
<span class="lightbox__credit"></span>
|
||||||
<span class="lightbox__counter"></span>
|
<span class="lightbox__counter"></span>
|
||||||
</figcaption>
|
</figcaption>
|
||||||
|
|
@ -47,9 +47,12 @@
|
||||||
image.width = link.dataset.width;
|
image.width = link.dataset.width;
|
||||||
image.height = link.dataset.height;
|
image.height = link.dataset.height;
|
||||||
image.alt = link.dataset.alt;
|
image.alt = link.dataset.alt;
|
||||||
// The alt text is shown as the caption, so screen readers get it once, from the image.
|
// The caption, or else the alt text. Shown alt text is hidden from screen readers, which
|
||||||
dialog.querySelector('.lightbox__alt').textContent = link.dataset.alt;
|
// already get it from the image.
|
||||||
dialog.querySelector('.lightbox__alt').setAttribute('aria-hidden', 'true');
|
const text = dialog.querySelector('.lightbox__text');
|
||||||
|
text.textContent = link.dataset.caption ?? link.dataset.alt;
|
||||||
|
if (link.dataset.caption) text.removeAttribute('aria-hidden');
|
||||||
|
else text.setAttribute('aria-hidden', 'true');
|
||||||
dialog.querySelector('.lightbox__credit').textContent = link.dataset.credit ?? '';
|
dialog.querySelector('.lightbox__credit').textContent = link.dataset.credit ?? '';
|
||||||
dialog.querySelector('.lightbox__counter').textContent =
|
dialog.querySelector('.lightbox__counter').textContent =
|
||||||
links.length > 1 ? `${index + 1} / ${links.length}` : '';
|
links.length > 1 ? `${index + 1} / ${links.length}` : '';
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,18 @@
|
||||||
{{- /*
|
{{- /*
|
||||||
One image in a gallery, see gallery.html. Params:
|
One image in a gallery, see gallery.html. Params:
|
||||||
src the image, a file in the page's folder (page resource) or in assets/
|
src the image, a file in the page's folder (page resource) or in assets/
|
||||||
alt what the image shows (required); also shown in the lightbox
|
alt what the image shows, for people who can't see it (required); the thumbnail link's
|
||||||
credit photographer, licence; shown under the thumbnail and in the lightbox
|
name, so it can't be empty. Shown in the lightbox when there is no caption.
|
||||||
|
caption context for everyone, shown under the thumbnail and in the lightbox (optional);
|
||||||
|
say something the alt text doesn't, or screen readers read the same text twice
|
||||||
|
credit photographer, licence; appended to the caption
|
||||||
*/ -}}
|
*/ -}}
|
||||||
{{- if ne .Parent.Name "gallery" -}}
|
{{- if ne .Parent.Name "gallery" -}}
|
||||||
{{- errorf "gallery-image: use it inside {{< gallery >}}: %s" .Position -}}
|
{{- errorf "gallery-image: use it inside {{< gallery >}}: %s" .Position -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- $src := .Get "src" -}}
|
{{- $src := .Get "src" -}}
|
||||||
{{- $alt := .Get "alt" -}}
|
{{- $alt := .Get "alt" -}}
|
||||||
|
{{- $caption := .Get "caption" -}}
|
||||||
{{- $credit := .Get "credit" -}}
|
{{- $credit := .Get "credit" -}}
|
||||||
{{- if not $alt -}}
|
{{- if not $alt -}}
|
||||||
{{- errorf "gallery-image: %q needs an alt text: %s" $src .Position -}}
|
{{- errorf "gallery-image: %q needs an alt text: %s" $src .Position -}}
|
||||||
|
|
@ -39,12 +43,15 @@ that for the original, but Hugo doesn't when it resizes. */ -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
<li class="gallery__item">
|
<li class="gallery__item">
|
||||||
<figure class="gallery__figure">
|
<figure class="gallery__figure">
|
||||||
<a class="gallery__link" href="{{ $image.RelPermalink }}" data-width="{{ $oriented.Width }}" data-height="{{ $oriented.Height }}" data-alt="{{ $alt }}"{{ with $credit }} data-credit="{{ . }}"{{ end }}>
|
<a class="gallery__link" href="{{ $image.RelPermalink }}" data-width="{{ $oriented.Width }}" data-height="{{ $oriented.Height }}" data-alt="{{ $alt }}"{{ with $caption }} data-caption="{{ . }}"{{ end }}{{ with $credit }} data-credit="{{ . }}"{{ end }}>
|
||||||
<img src="{{ $large.RelPermalink }}" srcset="{{ $small.RelPermalink }} {{ $small.Width }}w, {{ $large.RelPermalink }} {{ $large.Width }}w" sizes="{{ $sizes }}" width="{{ $large.Width }}" height="{{ $large.Height }}" alt="{{ $alt }}" loading="lazy" decoding="async">
|
<img src="{{ $large.RelPermalink }}" srcset="{{ $small.RelPermalink }} {{ $small.Width }}w, {{ $large.RelPermalink }} {{ $large.Width }}w" sizes="{{ $sizes }}" width="{{ $large.Width }}" height="{{ $large.Height }}" alt="{{ $alt }}" loading="lazy" decoding="async">
|
||||||
<span class="visually-hidden"> ({{ i18n "gallery_enlarge" }})</span>
|
<span class="visually-hidden"> ({{ i18n "gallery_enlarge" }})</span>
|
||||||
</a>
|
</a>
|
||||||
{{- with $credit }}
|
{{- if or $caption $credit }}
|
||||||
<figcaption class="gallery__credit">{{ . }}</figcaption>
|
<figcaption class="gallery__caption">
|
||||||
|
{{- with $caption }}{{ . }}{{ end }}
|
||||||
|
{{- with $credit }}{{ if $caption }} {{ end }}<span class="gallery__credit">{{ . }}</span>{{ end -}}
|
||||||
|
</figcaption>
|
||||||
{{- end }}
|
{{- end }}
|
||||||
</figure>
|
</figure>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue