github.com/choria-io/go-choria@v0.28.1-0.20240416190746-b3bf9c7d5a45/docs/themes/hugo-theme-relearn/layouts/partials/shortcodes/image.html (about) 1 {{- $page := .page }} 2 {{- if and (not $page) .context }} 3 {{- $page = .context }} 4 {{- 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 }} 5 {{- end }} 6 {{- $url := .url }} 7 {{- $title := .title }} 8 {{- $alt := .alt }} 9 {{- $effects := dict "border" false "lazy" true "lightbox" true "shadow" false }} 10 {{- if $page.Site.Params.imageeffects }} 11 {{- $effects = merge $effects $page.Site.Params.imageeffects }} 12 {{- end }} 13 {{- if $page.Params.imageEffects }} 14 {{- $effects = merge $effects $page.Params.imageEffects }} 15 {{- end }} 16 {{- $height := "auto" }} 17 {{- $width := "auto" }} 18 {{- $attributes := .attributes | default dict }} 19 {{- $dest_url := urls.Parse $url }} 20 {{- $dest_path := $dest_url.Path }} 21 {{- $image := "" }} 22 {{- if not $dest_url.IsAbs }} 23 {{- with or 24 ($page.Resources.Get $dest_url.Path) 25 (resources.Get $dest_url.Path) 26 }} 27 {{- $image = . }} 28 {{- end }} 29 {{- with $image }} 30 {{- $url = $image.RelPermalink }} 31 {{- with $dest_url.RawQuery }} 32 {{- $url = printf "%s?%s" $url . }} 33 {{- end }} 34 {{- with $dest_url.Fragment }} 35 {{- $url = printf "%s#%s" $url . }} 36 {{- end }} 37 {{- else }} 38 {{- if eq $page.Site.Params.image.errorlevel "warning" }} 39 {{- warnf "%q: image '%s' is not a resource but linked anyways" $page.File.Filename .url }} 40 {{- else if eq $page.Site.Params.image.errorlevel "error" }} 41 {{- errorf "%q: image '%s' is not a resource" $page.File.Filename .url }} 42 {{- end }} 43 {{- end }} 44 {{- end }} 45 {{- if $dest_url.RawQuery }} 46 {{- if $dest_url.Query.Has "classes" }} 47 {{- $classes := slice | append (split ($dest_url.Query.Get "classes") ",") }} 48 {{- range $classes }} 49 {{- $k := . }} 50 {{- $v := true }} 51 {{- if strings.HasPrefix $k "no" }} 52 {{- $k := strings.TrimPrefix "no" $k }} 53 {{- $v := false }} 54 {{- end }} 55 {{- $effects = merge $effects (dict $k $v) }} 56 {{- end }} 57 {{- end }} 58 {{- if $dest_url.Query.Has "featherlight" }} 59 {{- 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 }} 60 {{- $effects = merge $effects (dict "lightbox" (ne ($dest_url.Query.Get "featherlight") "false")) }} 61 {{- end }} 62 {{- range $k, $v := $effects }} 63 {{- if $dest_url.Query.Has $k }} 64 {{- $effects = merge $effects (dict $k (ne ($dest_url.Query.Get $k) "false")) }} 65 {{- end }} 66 {{- end }} 67 {{- with $dest_url.Query.Get "height" }} 68 {{- $height = . }} 69 {{- end }} 70 {{- with $dest_url.Query.Get "width" }} 71 {{- $width = . }} 72 {{- end }} 73 {{- end }} 74 {{- $classes := slice }} 75 {{- range $k, $v := $effects }} 76 {{- $c := printf "%s%s" (cond $v "" "no") $k }} 77 {{- $classes = $classes | append $c }} 78 {{- end }} 79 {{- $id := cond (or (eq .id nil) (eq .id "")) (partial "make-random-md5.hugo" $page) .id }} 80 {{- $attributes = merge $attributes (dict "alt" $alt "src" $url "title" $title) }} 81 {{- if $effects.lazy }} 82 {{- $attributes = merge $attributes (dict "loading" "lazy") }} 83 {{- end }} 84 {{- if $effects.lightbox -}} 85 <a href="#R-image-{{ $id }}" class="lightbox-link"> 86 {{- end }} 87 {{- $attributes_figure := merge $attributes (dict "class" (delimit (append (index $attributes "class" | default slice) "figure-image" $classes) " ")) }} 88 {{- $attributes_figure = merge $attributes_figure (dict "style" (delimit (slice (index $attributes "style") (printf "height: %s; width: %s;" $height $width)) " ")) -}} 89 <img 90 {{- range $k, $v := $attributes_figure }} 91 {{- if $v }} 92 {{- printf " %s=%q" $k $v | safeHTMLAttr }} 93 {{- end }} 94 {{- end }}> 95 {{- if $effects.lightbox -}} 96 </a> 97 <a href="javascript:history.back();" class="lightbox-back" id="R-image-{{ $id }}"> 98 {{- $attributes_lightbox := merge $attributes (dict "class" (delimit (append (index $attributes "class" | default slice) "lightbox-image" $classes) " ")) -}} 99 <img 100 {{- range $k, $v := $attributes_lightbox }} 101 {{- if $v }} 102 {{- printf " %s=%q" $k $v | safeHTMLAttr }} 103 {{- end }} 104 {{- end }}></a> 105 {{- end }}