From ed40ddd27e9f78c26be4214054cf5e016588a8c8 Mon Sep 17 00:00:00 2001 From: Sped0n Date: Fri, 3 Nov 2023 09:49:40 +0800 Subject: [PATCH] chore(imageJSON.html): add alt attribute to images in imageJSON partial to improve accessibility --- exampleSite/content/Erwitt/index.md | 2 ++ exampleSite/content/Gruyaert/index.md | 2 ++ .../content/{Info.md => Info/index.md} | 4 ++- exampleSite/content/Webb/index.md | 2 ++ layouts/partials/resources/imageJSON.html | 27 ++++++++++++------- 5 files changed, 26 insertions(+), 11 deletions(-) rename exampleSite/content/{Info.md => Info/index.md} (96%) diff --git a/exampleSite/content/Erwitt/index.md b/exampleSite/content/Erwitt/index.md index f5d6859..d91991d 100644 --- a/exampleSite/content/Erwitt/index.md +++ b/exampleSite/content/Erwitt/index.md @@ -6,4 +6,6 @@ menu: main: weight: 3 identifier: Erwitt + title: Erwitt +unifiedAlt: '© Elliott Erwitt' --- diff --git a/exampleSite/content/Gruyaert/index.md b/exampleSite/content/Gruyaert/index.md index 0fa7178..3a1695e 100644 --- a/exampleSite/content/Gruyaert/index.md +++ b/exampleSite/content/Gruyaert/index.md @@ -6,4 +6,6 @@ menu: main: weight: 1 identifier: Gruyaert + title: Gruyaert +unifiedAlt: '© Harry Gruyaert' --- diff --git a/exampleSite/content/Info.md b/exampleSite/content/Info/index.md similarity index 96% rename from exampleSite/content/Info.md rename to exampleSite/content/Info/index.md index 6b57491..991316a 100644 --- a/exampleSite/content/Info.md +++ b/exampleSite/content/Info/index.md @@ -1,11 +1,13 @@ --- type: _default layout: single -url: /info/ +url: /Info/ menu: main: weight: 4 identifier: Info + title: Info +unifiedAlt: '' --- Bridget is a _minimal_ Hugo theme designed for photographers / visual artists. diff --git a/exampleSite/content/Webb/index.md b/exampleSite/content/Webb/index.md index a5e27ee..15d4bb1 100644 --- a/exampleSite/content/Webb/index.md +++ b/exampleSite/content/Webb/index.md @@ -6,4 +6,6 @@ menu: main: weight: 2 identifier: Webb + title: Webb +unifiedAlt: '© Alex Webb' --- diff --git a/layouts/partials/resources/imageJSON.html b/layouts/partials/resources/imageJSON.html index e10069f..c3ee9bb 100644 --- a/layouts/partials/resources/imageJSON.html +++ b/layouts/partials/resources/imageJSON.html @@ -1,15 +1,22 @@ {{- $Page := .Page -}} +{{- $params := .Page.Params | merge .Site.Params.Page -}} -{{ $gallery := site.GetPage .Path }} -{{ with $gallery.Resources.ByType "image" }} - {{ $index := len . }} - {{ $Page.Scratch.Add "img" slice }} - {{ range . }} - {{ $index = sub $index 1 }} - {{ $lores := .Resize "800x webp Lanczos q60" }} - {{ $hires := .Resize "2500x webp Lanczos q75" }} - {{ $Page.Scratch.Add "img" (dict +{{- $gallery := site.GetPage .Path -}} +{{- with $gallery.Resources.ByType "image" -}} + {{- $index := len . -}} + {{- $Page.Scratch.Add "img" slice -}} + {{- range sort . "Name" "desc" -}} + {{- $image := . -}} + {{- $index = sub $index 1 -}} + {{- $alt := .Name -}} + {{- with $params.unifiedAlt -}} + {{- $alt = . -}} + {{- end -}} + {{- $lores := .Resize "800x webp Lanczos q60" -}} + {{- $hires := .Resize "2500x webp Lanczos q75" -}} + {{- $Page.Scratch.Add "img" (dict "index" (int $index) + "alt" (string $alt) "loUrl" (string $lores.RelPermalink) "loImgH" (int $lores.Height) "loImgW" (int $lores.Width) @@ -17,7 +24,7 @@ "hiImgH" (int $hires.Height) "hiImgW" (int $hires.Width) ) - }} + -}} {{- end -}} {{- end -}}