mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-27 09:43:06 +00:00
46 lines
No EOL
1.5 KiB
HTML
46 lines
No EOL
1.5 KiB
HTML
{{- $context := .context }}
|
|
{{- $url := .url }}
|
|
{{- $title := .title }}
|
|
{{- $alt := .alt }}
|
|
{{- $classes := "" }}
|
|
{{- $featherlight := true }}
|
|
{{- $height := "auto" }}
|
|
{{- $width := "auto" }}
|
|
{{- $dest_url := urls.Parse $url }}
|
|
{{- $dest_path := $dest_url.Path }}
|
|
{{- $image := $context.Resources.GetMatch $dest_path }}
|
|
{{- if not $image }}
|
|
{{- $image = .Resources.GetMatch $dest_path }}
|
|
{{- end }}
|
|
{{- if not $image }}
|
|
{{- $image = .Resources.GetRemote $url }}
|
|
{{- end }}
|
|
{{- if $image }}
|
|
{{- $url = $image.RelPermalink }}
|
|
{{- if $dest_url.RawQuery }}
|
|
{{- $url = printf "%s?%s" $url $dest_url.RawQuery }}
|
|
{{- end }}
|
|
{{- $height = printf "%dpx" $image.Height }}
|
|
{{- $width = printf "%dpx" $image.Width }}
|
|
{{- end }}
|
|
{{- if $dest_url.RawQuery }}
|
|
{{- $classes = (replaceRE "\\s+" " " (replaceRE "," " " ($dest_url.Query.Get "classes") ) ) }}
|
|
{{- $featherlight = (ne ($dest_url.Query.Get "featherlight") "false") }}
|
|
{{- if or ($dest_url.Query.Get "height") ($dest_url.Query.Get "width") }}
|
|
{{- $height = "auto" }}
|
|
{{- $width = "auto" }}
|
|
{{- end }}
|
|
{{- with $dest_url.Query.Get "height" }}
|
|
{{ $height = . }}
|
|
{{- end }}
|
|
{{- with $dest_url.Query.Get "width" }}
|
|
{{ $width = . }}
|
|
{{- end }}
|
|
{{- end }}
|
|
{{- if $featherlight }}
|
|
<a href="{{ $url | safeURL }}" data-featherlight="image">
|
|
{{- end }}
|
|
<img src="{{ $url | safeURL }}" alt="{{ $alt }}"{{ with $title }} title="{{ . }}"{{ end }}{{ with $classes }} class="{{ . }}"{{ end }} style="height: {{ $height }}; width: {{ $width }};" loading="lazy">
|
|
{{- if $featherlight }}
|
|
</a>
|
|
{{- end }} |