add alt tag to image shortcode
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Robert Kaussow 2019-02-07 16:25:14 +01:00
parent 4d151144e3
commit cbaa641826
1 changed files with 6 additions and 1 deletions

View File

@ -1,6 +1,7 @@
{{ $original := .Page.Resources.GetMatch (printf "*%s*" (.Get 0)) }}
{{ $command := strings.ToLower (printf "%s" (.Get 1)) }}
{{ $options := .Get 2 }}
{{ $customAlt := .Get 3 }}
{{ if eq $command "fit"}}
{{ .Scratch.Set "image" ($original.Fit $options) }}
{{ else if eq $command "resize"}}
@ -11,9 +12,13 @@
{{ errorf "Invalid image processing command: Must be one of Fit, Fill or Resize. Is: %s" ($command)}}
{{ end }}
{{ $image := .Scratch.Get "image" }}
{{ $imgAlt := $original.Title }}
{{ if $customAlt }}
{{ $imgAlt = $customAlt }}
{{ end }}
<figure class="post-figure">
<a href="{{ $original.RelPermalink }}">
<img class="post-figure__img" src="{{ $image.RelPermalink }}" width="{{ $image.Width }}" height="{{ $image.Height }}">
<img class="post-figure__img" src="{{ $image.RelPermalink }}" alt="{{ $imgAlt }}" width="{{ $image.Width }}" height="{{ $image.Height }}">
</a>
<figcaption class="post-figure__caption">
<small>