sitoctt/layouts/partials/ImgButton.html

37 lines
1.1 KiB
HTML

{{- $extended := (eq .Context.Params.extended true) -}}
{{- $size := (or .size "88x31") -}}
{{- $sizes := (split $size "x") -}}
{{- $alt := (or (and .alt (printf "[%s]" .alt)) "") -}}
{{- $src := (or
.src
(printf `%s/Media/Buttons/%s/%s`
(partial "assetsRoot.html")
$size
.srcRelative)) -}}
{{- $style := (or .style "") -}}
{{- if (and (not $style) (not (eq (index (last 1 (split $src ".")) 0) "svg"))) -}}
{{- $style = "image-rendering: pixelated;" -}}
{{- end -}}
{{/* TODO: maybe set rendering via a class instead of inline CSS? */}}
{{- $img := (printf `<img src="%s" style="%s" alt="%s" title="%s" width="%spx" height="%spx" decoding="%s" />`
$src $style
$alt $alt
(index $sizes 0) (index $sizes 1)
(or .decoding "async")
) | safeHTML -}}
{{- $html := $img -}}
{{- if $extended -}}
{{- $html = (printf "%s <span>%s</span>" $img .alt) | safeHTML -}}
{{- if .oc -}}
{{- $html = (printf "%s [OC]" $html) | safeHTML -}}
{{- end -}}
{{- end -}}
{{- if .href -}}
{{- $html = (partial "anchor.html" (dict
"Inner" $html
"Params" .)) -}}
{{- end -}}
{{ if $extended }}<li>{{ end }}
{{ $html }}
{{ if $extended }}</li>{{ end }}