This repository has been archived on 2024-11-25. You can view files and clone it, but cannot push or open issues or pull requests.
2023-10-12 14:01:05 +02:00

54 lines
2.5 KiB
HTML

{{- /* lightgallery */ -}}
{{- $src := .Src -}}
{{- $width := .Width -}}
{{- $height := .Height -}}
{{- with dict "Path" $src "Resources" .Resources | partial "function/resource.html" -}}
{{- $src = .RelPermalink -}}
{{- /* Resources can not get width and height of image for svg type */ -}}
{{- if (not $.Width) | and (not $.Height) | and (ne .MediaType.SubType "svg") -}}
{{- $width = .Width -}}
{{- $height = .Height -}}
{{- end -}}
{{- end -}}
{{- $small := .SrcSmall | default $src -}}
{{- with dict "Path" .SrcSmall "Resources" .Resources | partial "function/resource.html" -}}
{{- $small = .RelPermalink -}}
{{- end -}}
{{- $large := .SrcLarge | default $src -}}
{{- with dict "Path" .SrcLarge "Resources" .Resources | partial "function/resource.html" -}}
{{- $large = .RelPermalink -}}
{{- end -}}
{{- $alt := .Alt | default $src -}}
{{- $caption := .Caption | default $alt -}}
{{- $loading := .Loading | default "lazy" -}}
{{- $commonScript := "this.title=this.dataset.title;this.alt=this.dataset.alt;for(const a of ['style','data-title','data-alt','onerror','onload']){this.removeAttribute(a);}" -}}
{{- $onload := printf " onload=\"%vthis.dataset.lazyloaded='';\"" $commonScript | safeHTMLAttr -}}
{{- $onerror := printf " onerror=\"%v\"" $commonScript | safeHTMLAttr -}}
{{- $style := printf " style=\"background: url(%v) no-repeat center;\"" (resources.Get "svg/loading.svg" | minify).RelPermalink | safeHTMLAttr -}}
{{- if eq $loading "eager" -}}
{{- $onload = "" -}}
{{- $onerror = "" -}}
{{- $style = "" -}}
{{- end -}}
{{- if .Linked -}}
<a class="lightgallery" href="{{ $large | safeURL }}" data-thumbnail="{{ $small | safeURL }}"{{ with $caption }} data-sub-html="<h2>{{ . }}</h2>{{ with $.Title }}<p>{{ . }}</p>{{ end }}"{{ end }}{{ with .Rel }} rel="{{ . }}"{{ end }}>
{{- end -}}
<img loading="{{ $loading }}" src="{{ .Src | safeURL }}" srcset="{{ $small | safeURL }}, {{ .Src | safeURL }} 1.5x, {{ $large | safeURL }} 2x" sizes="auto"
{{- if eq $loading "eager" }} title="{{ .Title | default $alt }}" alt="{{ $alt }}"
{{- else }} data-title="{{ .Title | default $alt }}" data-alt="{{ $alt }}"{{- end -}}
{{- with $width }} width="{{ . }}"{{- end -}}
{{- with $height }} height="{{ . }}"{{- end -}}
{{- with .Class }} class="{{ . }}"{{- end -}}
{{- with $style -}}{{ . }}{{- end -}}
{{- with $onload -}}{{ . }}{{- end -}}
{{- with $onerror -}}{{ . }}{{- end -}}
{{- with .Height }} data-h{{- end -}}
/>
{{- if .Linked -}}
</a>
{{- end -}}