congo/layouts/_default/_markup/render-image.html

31 lines
1.0 KiB
HTML
Raw Permalink Normal View History

{{ $url := urls.Parse .Destination }}
{{ $altText := .Text }}
{{ $caption := .Title }}
{{ $class := "mx-auto my-0 rounded-md" }}
{{ $file := $url.Path }}
{{ $img := .Page.Resources.GetMatch $file }}
{{- if and (not $img) .Page.File }}
2023-12-26 00:22:55 +00:00
{{ $path := path.Join .Page.File.Dir $file }}
{{ $img = resources.Get $path }}
{{ end -}}
2023-11-26 13:38:27 +00:00
{{/* https://github.com/gohugoio/hugo/pull/10666 */}}
2023-11-26 01:23:34 +00:00
{{- $params := $url.Query -}}
2023-11-26 13:23:42 +00:00
{{- $x2Param := $params.Get "2x" -}}
2023-11-26 01:23:34 +00:00
{{- $x2 := false -}}
{{- if eq $x2Param "true" -}}
2023-12-26 00:22:55 +00:00
{{- $x2 = true -}}
2023-11-26 01:23:34 +00:00
{{- end -}}
<figure>
{{- with $img -}}
2023-11-29 13:51:44 +00:00
{{ $lazy := $.Page.Site.Params.enableImageLazyLoading | default true }}
{{ $webp := $.Page.Site.Params.enableImageWebp | default true }}
{{ partial "picture.html" (dict "img" . "alt" $altText "class" $class "x2" $x2 "lazy" $lazy "webp" $webp) }}
{{- else -}}
2023-12-26 00:22:55 +00:00
<img src="{{ .Destination | safeURL }}" alt="{{ $altText }}" class="{{ $class }}" />
{{- end -}}
{{ with $caption }}<figcaption class="text-center">{{ . | markdownify }}</figcaption>{{ end }}
</figure>