mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-27 01:33:04 +00:00
833ccac2d2
- resolve render hook destination with leading ./ - adjust variable naming
102 lines
No EOL
4 KiB
HTML
102 lines
No EOL
4 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/basics/migration#5180" $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 }}
|
|
{{- if eq $page.Site.Params.image.errorlevel "warning" }}
|
|
{{- warnf "%q: image '%s' is not a resource but linked anyways" $page.File.Filename .url }}
|
|
{{- else if eq $page.Site.Params.image.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/basics/migration#5110" $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 "make-random-md5.hugo" $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 }} |