Files
caldwell/layouts/partials/components/image/process.html
2025-09-13 20:35:50 +00:00

42 lines
1.2 KiB
HTML

{{- $image := .image -}}
{{- $page := .page -}}
{{- $src := $image -}}
{{- $caption := "" -}}
{{- $title := "" -}}
{{- $alt := "" -}}
{{- if reflect.IsMap $image -}}
{{- $src = $image.src | default "" -}}
{{- $caption = $image.caption | default "" -}}
{{- $title = $image.title | default $caption | default "" | plainify -}}
{{- $alt = $image.alt | default $title | default "" | plainify -}}
{{- end -}}
{{- if $src -}}
{{- $isRemote := strings.HasPrefix $src "http" -}}
{{- if $isRemote -}}
{{- $remote := resources.GetRemote $src -}}
{{- $image = resources.Copy (printf "static/3rd-party/%s" $remote.Name) $remote -}}
{{- else -}}
{{- $image = ($page.Resources.Get $src) | default (resources.Get $src) -}}
{{- end -}}
{{- end -}}
{{- $result := "" -}}
{{- with $image -}}
{{- $full := . | images.Filter (images.Process "webp q90") -}}
{{- $thumb := . -}}
{{- if gt .Width 2000 -}}
{{- $thumb = . | images.Filter (images.Process "resize 2000x webp q75") -}}
{{- else -}}
{{- $thumb = . | images.Filter (images.Process "webp q75") -}}
{{- end -}}
{{- $result = dict "full" $full "thumb" $thumb "caption" $caption "title" $title "alt" $alt -}}
{{- end -}}
{{- return $result -}}