use image alt wherever possible

This commit is contained in:
Gabriele Musco 2022-10-24 08:16:12 +02:00
parent bcff415581
commit 3706ace5e8
No known key found for this signature in database
GPG Key ID: 1068D795C80E51DE
4 changed files with 9 additions and 7 deletions

View File

@ -19,7 +19,8 @@
"summary" (or .Params.description .Summary)
"text" (lower .Plain)
"link" .Permalink
"image" $image) }}
"image" $image
"imageAlt" (or .Params.Alt "")) }}
{{ end }}
"pages": {{ $mscratch.Get "articles" | jsonify }}
}

View File

@ -25,7 +25,8 @@
"tags" (sort (or .Params.tags slice))
"summary" (or .Params.description .Summary)
"link" .Permalink
"image" $image) }}
"image" $image
"imageAlt" (or .Params.Alt "")) }}
{{ end }}
"articles": {{ $mscratch.Get "articles" | jsonify }},
"test": "{{range $postsList}}{{.Title}} {{end}}",

View File

@ -18,9 +18,9 @@
{{ if .Params.Image }}
<a class="unstyledLink" href="{{ .Permalink }}">
{{ if or (hasPrefix .Params.Image "/") (hasPrefix .Params.Image "http://") (hasPrefix .Params.Image "https://") }}
<img src="{{ .Params.Image }}" />
<img src="{{ .Params.Image }}" alt="{{ .Params.Alt }}" />
{{ else }}
<img src="/{{ path.Join .File.Dir .Params.Image }}" />
<img src="/{{ path.Join .File.Dir .Params.Image }}" alt="{{ .Params.Alt }}" />
{{ end }}
</a>
{{ end }}

View File

@ -8,9 +8,9 @@
}
return res;
}
function renderImage(image, link) {
function renderImage(image, link, alt) {
if (!image) return '';
return `<a href="${link}"><img src="${image}" /></a>`;
return `<a href="${link}"><img src="${image}" alt="${alt}" /></a>`;
}
function renderSingleArticle(article) {
return `
@ -27,7 +27,7 @@
{{ end }}
</p>
{{ if .Site.Params.imageInArticlePreview }}
${renderImage(article.image, article.link)}
${renderImage(article.image, article.link, article.imageAlt)}
{{ end }}
{{ if (site.Params.articleSummary | default true) }}
<div class="articlePreview">