mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-23 15:57:57 +00:00
103 lines
No EOL
4.1 KiB
HTML
103 lines
No EOL
4.1 KiB
HTML
{{- /* based on Hugo 0.125.5 render-image.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/introduction/releasenotes/5/#5-18-0" $page.File.Filename }}
|
|
{{- end }}
|
|
{{- $title := .title }}
|
|
{{- $alt := .alt }}
|
|
{{- $effects := dict "border" false "lazy" true "lightbox" true "shadow" false }}
|
|
{{- if $page.Site.Params.imageeffects }}
|
|
{{- $effects = merge $effects $page.Site.Params.imageeffects }}
|
|
{{- end }}
|
|
{{- if $page.Params.imageEffects }}
|
|
{{- $effects = merge $effects $page.Params.imageEffects }}
|
|
{{- end }}
|
|
{{- $height := "auto" }}
|
|
{{- $width := "auto" }}
|
|
{{- $attributes := .attributes | default dict }}
|
|
{{- $u := urls.Parse .url }}
|
|
{{- $src := $u.String }}
|
|
{{- if not $u.IsAbs }}
|
|
{{- $path := strings.TrimPrefix "./" $u.Path }}
|
|
{{- with or
|
|
($page.Resources.Get $path)
|
|
(resources.Get $path)
|
|
}}
|
|
{{- $src = .RelPermalink }}
|
|
{{- with $u.RawQuery }}
|
|
{{- $src = printf "%s?%s" $src . }}
|
|
{{- end }}
|
|
{{- with $u.Fragment }}
|
|
{{- $src = printf "%s#%s" $src . }}
|
|
{{- end }}
|
|
{{- else }}
|
|
{{- $errorlevel := or $page.Params.image.errorlevel $page.Site.Params.image.errorlevel }}
|
|
{{- if eq $errorlevel "warning" }}
|
|
{{- warnf "%q: image '%s' is not a resource but linked anyways" $page.File.Filename .url }}
|
|
{{- else if eq $errorlevel "error" }}
|
|
{{- errorf "%q: image '%s' is not a resource" $page.File.Filename .url }}
|
|
{{- end }}
|
|
{{- end }}
|
|
{{- end }}
|
|
{{- if $u.RawQuery }}
|
|
{{- if $u.Query.Has "classes" }}
|
|
{{- $classes := slice | append (split ($u.Query.Get "classes") ",") }}
|
|
{{- range $classes }}
|
|
{{- $k := . }}
|
|
{{- $v := true }}
|
|
{{- if strings.HasPrefix $k "no" }}
|
|
{{- $k := strings.TrimPrefix "no" $k }}
|
|
{{- $v := false }}
|
|
{{- end }}
|
|
{{- $effects = merge $effects (dict $k $v) }}
|
|
{{- end }}
|
|
{{- end }}
|
|
{{- if $u.Query.Has "featherlight" }}
|
|
{{- warnf "%q: DEPRECATED usage of 'featherlight' image CSS class found, use 'lightbox' instead; see https://mcshelby.github.io/hugo-theme-relearn/introduction/releasenotes/5/#5-11-0" $page.File.Filename }}
|
|
{{- $effects = merge $effects (dict "lightbox" (ne ($u.Query.Get "featherlight") "false")) }}
|
|
{{- end }}
|
|
{{- range $k, $v := $effects }}
|
|
{{- if $u.Query.Has $k }}
|
|
{{- $effects = merge $effects (dict $k (ne ($u.Query.Get $k) "false")) }}
|
|
{{- end }}
|
|
{{- end }}
|
|
{{- with $u.Query.Get "height" }}
|
|
{{- $height = . }}
|
|
{{- end }}
|
|
{{- with $u.Query.Get "width" }}
|
|
{{- $width = . }}
|
|
{{- end }}
|
|
{{- end }}
|
|
{{- $classes := slice }}
|
|
{{- range $k, $v := $effects }}
|
|
{{- $c := printf "%s%s" (cond $v "" "no") $k }}
|
|
{{- $classes = $classes | append $c }}
|
|
{{- end }}
|
|
{{- $id := cond (or (eq .id nil) (eq .id "")) (partial "_relearn/makeRandomMd5.gotmpl" $page) .id }}
|
|
{{- $attributes = merge $attributes (dict "alt" $alt "src" $src "title" ($title | transform.HTMLEscape)) }}
|
|
{{- if $effects.lazy }}
|
|
{{- $attributes = merge $attributes (dict "loading" "lazy") }}
|
|
{{- end }}
|
|
{{- if $effects.lightbox -}}
|
|
<a href="#R-image-{{ $id }}" class="lightbox-link">
|
|
{{- end }}
|
|
{{- $attributes_figure := merge $attributes (dict "class" (delimit (append (index $attributes "class" | default slice) "figure-image" $classes) " ")) }}
|
|
{{- $attributes_figure = merge $attributes_figure (dict "style" (delimit (slice (index $attributes "style") (printf "height: %s; width: %s;" $height $width)) " ")) -}}
|
|
<img
|
|
{{- range $k, $v := $attributes_figure }}
|
|
{{- if $v }}
|
|
{{- printf " %s=%q" $k $v | safeHTMLAttr }}
|
|
{{- end }}
|
|
{{- end }}>
|
|
{{- if $effects.lightbox -}}
|
|
</a>
|
|
<a href="javascript:history.back();" class="lightbox-back" id="R-image-{{ $id }}">
|
|
{{- $attributes_lightbox := merge $attributes (dict "class" (delimit (append (index $attributes "class" | default slice) "lightbox-image" $classes) " ")) -}}
|
|
<img
|
|
{{- range $k, $v := $attributes_lightbox }}
|
|
{{- if $v }}
|
|
{{- printf " %s=%q" $k $v | safeHTMLAttr }}
|
|
{{- end }}
|
|
{{- end }}></a>
|
|
{{- end }} |