mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-27 09:43:06 +00:00
53 lines
No EOL
2.2 KiB
HTML
53 lines
No EOL
2.2 KiB
HTML
{{- $page := .page }}
|
|
{{- if and (not $page) .context }}
|
|
{{- $page = .context }}
|
|
{{- warnf "%q: DEPRECATED parameter 'context' for shortcode 'image' found, use 'page' instead; see https://mcshelby.github.io/hugo-theme-relearn/basics/migration/#5180" $page.File.Path }}
|
|
{{- end }}
|
|
{{- $url := .url }}
|
|
{{- $title := .title }}
|
|
{{- $alt := .alt }}
|
|
{{- $classes := slice }}
|
|
{{- $lightbox := true }}
|
|
{{- $height := "auto" }}
|
|
{{- $width := "auto" }}
|
|
{{- $dest_url := urls.Parse $url }}
|
|
{{- $dest_path := $dest_url.Path }}
|
|
{{- $image := $page.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 }}
|
|
{{- end }}
|
|
{{- if $dest_url.RawQuery }}
|
|
{{- if $dest_url.Query.Get "classes" }}
|
|
{{- $classes = $classes | append (split ($dest_url.Query.Get "classes") ",") }}
|
|
{{- end }}
|
|
{{- if $dest_url.Query.Has "featherlight" }}
|
|
{{- warnf "%q: DEPRECATED usage of 'featherlight' image CSS class found, use 'lightbox' instead; see https://mcshelby.github.io/hugo-theme-relearn/basics/migration/#5110" $page.File.Path }}
|
|
{{- end }}
|
|
{{- $lightbox = and (ne ($dest_url.Query.Get "lightbox") "false") (ne ($dest_url.Query.Get "featherlight") "false") }}
|
|
{{- with $dest_url.Query.Get "height" }}
|
|
{{ $height = . }}
|
|
{{- end }}
|
|
{{- with $dest_url.Query.Get "width" }}
|
|
{{ $width = . }}
|
|
{{- end }}
|
|
{{- end }}
|
|
{{- $id := cond (or (eq .id nil) (eq .id "")) (partial "make-random-md5.hugo" $page) .id }}
|
|
{{- if $lightbox }}
|
|
<a href="#image-{{ $id }}" class="lightbox-link">
|
|
{{- end }}
|
|
<img src="{{ $url | safeURL }}" alt="{{ $alt }}"{{ with $title }} title="{{ . }}"{{ end }}{{ if len ($classes) }} class="{{ delimit $classes " " }}"{{ end }} style="height: {{ $height }}; width: {{ $width }};" loading="lazy">
|
|
{{- if $lightbox }}
|
|
</a>
|
|
<a href="javascript:history.back();" class="lightbox" id="image-{{ $id }}">
|
|
<img src="{{ $url | safeURL }}" alt="{{ $alt }}"{{ with $title }} title="{{ . }}"{{ end }} class="lightbox-image" loading="lazy">
|
|
</a>
|
|
{{- end }} |