I may be dense and overlooking it, but does Hugo support defining alt
when using the images=[]
array front matter? This is particularly a concern for web accessibility.
Ideally, I’d imagine it would be something like this:
images=[
["img1.png","alt1"],
["img2.png","alt2"]
]
or is images=[]
really only intended for twitter cards and open graph and not theme use?
zwbetz
August 21, 2019, 1:51am
2
It can be done with the appropriate template code
1 Like
Not and function for twitter cards.
images = [["static/img/picture.jpg","test"]]
returns this:
<meta name="twitter:image" content=""/>
rather than this:
<meta name="twitter:image" content="static/img/picture.jpg"/>
EDIT: Beyond the fact that your “answer” is less than helpful (at least link to something or use any word that would help someone search).
zwbetz
August 21, 2019, 2:16am
4
Show us the template code you’re using. Then we can go from there.
Internal Twitter Card Template
{{- with $.Params.images -}}
<meta name="twitter:card" content="summary_large_image"/>
<meta name="twitter:image" content="{{ index . 0 | absURL }}"/>
{{ else -}}
{{- $images := $.Resources.ByType "image" -}}
{{- $featured := $images.GetMatch "*feature*" -}}
{{- $featured := cond (ne $featured nil) $featured ($images.GetMatch "{*cover*,*thumbnail*}") -}}
{{- with $featured -}}
<meta name="twitter:card" content="summary_large_image"/>
<meta name="twitter:image" content="{{ $featured.Permalink }}"/>
{{- else -}}
{{- with $.Site.Params.images -}}
<meta name="twitter:card" content="summary_large_image"/>
<meta name="twitter:image" content="{{ index . 0 | absURL }}"/>
{{ else -}}
<meta name="twitter:card" content="summary"/>
{{- end -}}
{{- end -}}
{{- end }}
<meta name="twitter:title" content="{{ .Title }}"/>
This file has been truncated. show original
zwbetz
August 21, 2019, 2:48am
6
I see. So you’ll want to copy that internal template code to your own partial. Then you can add in the alt
attr logic.