1
0
forked from BgLUG/bglug.it
bglug.it/layouts/_default/_markup/render-image.html
paspo 1dfcfed27a fix img tooltip (#193)
fixes #192

Reviewed-on: BgLUG/bglug.it#193
Co-authored-by: paspo <paolo@asperti.com>
Co-committed-by: paspo <paolo@asperti.com>
2024-08-11 18:33:06 +00:00

37 lines
1.1 KiB
HTML

<figure>
{{- $u := urls.Parse .Destination -}}
{{- $src := $u.String -}}
{{- $figcaption := .Title | markdownify -}}
{{- $captionWidth := 0 -}}
{{- if not $u.IsAbs -}}
{{- $path := strings.TrimPrefix "./" $u.Path }}
{{- with or (.PageInner.Resources.Get $path) (resources.Get $path) -}}
{{- if gt .Width 1400 -}}
{{- $src = (.Resize "1400x webp q50").RelPermalink -}}
{{- else -}}
{{- $src = (.Process "webp q50").RelPermalink -}}
{{- end -}}
{{- with $u.RawQuery -}}
{{- $src = printf "%s?%s" $src . -}}
{{- end -}}
{{- with $u.Fragment -}}
{{- $src = printf "%s#%s" $src . -}}
{{- end -}}
{{- $captionWidth = .Width -}}
{{- end -}}
{{- end -}}
{{- $attributes := merge .Attributes (dict "alt" .Text "src" $src "title" .Text) -}}
<img
{{- range $k, $v := $attributes -}}
{{- if $v -}}
{{- printf " %s=%q" $k $v | safeHTMLAttr -}}
{{- end -}}
{{- end -}}>
{{- with $figcaption -}}
<figcaption
{{ with $captionWidth }} style="max-width: {{- . -}}px;"
{{- end -}}>{{- . -}}</figcaption>
{{- end -}}
</figure>
{{- /**/ -}}