|
| 1 | +{{ $disableImageOptimization := .Site.Params.disableImageOptimization | default false }} |
| 2 | +{{ if .Get "default" }} |
| 3 | + {{ partial "hugo-embedded/shortcodes/figure-default.html" . }} |
| 4 | +{{ else }} |
| 5 | + {{- $url := urls.Parse (.Get "src") }} |
| 6 | + {{- $altText := .Get "alt" }} |
| 7 | + {{- $caption := .Get "caption" }} |
| 8 | + {{- $href := .Get "href" }} |
| 9 | + {{- $class := .Get "class" }} |
| 10 | + {{- $target := .Get "target" | default "_blank" }} |
| 11 | + {{- $nozoom := .Get "nozoom" | default false -}} |
| 12 | + |
| 13 | + <figure> |
| 14 | + {{- with $href }}<a href="{{ . }}" {{ with $target }}target="{{ . }}"{{ end }}>{{ end -}} |
| 15 | + {{- if findRE "^https?" $url.Scheme }} |
| 16 | + <img class="my-0 rounded-md{{ with $nozoom }} nozoom{{ end }}{{ with $class }} {{ . }}{{ end }}" src="{{ $url.String }}" alt="{{ $altText }}" /> |
| 17 | + {{- else }} |
| 18 | + {{- $resource := "" }} |
| 19 | + {{- if $.Page.Resources.GetMatch ($url.String) }} |
| 20 | + {{- $resource = $.Page.Resources.GetMatch ($url.String) }} |
| 21 | + {{- else if resources.GetMatch ($url.String) }} |
| 22 | + {{- $resource = resources.Get ($url.String) }} |
| 23 | + {{- end }} |
| 24 | + {{- with $resource }} |
| 25 | + {{- if or $disableImageOptimization (eq .MediaType.SubType "svg")}} |
| 26 | + <img |
| 27 | + class="my-0 rounded-md{{ with $nozoom }} nozoom{{ end }}{{ with $class }} {{ . }}{{ end }}" |
| 28 | + src="{{ .RelPermalink }}" |
| 29 | + alt="{{ $altText }}" |
| 30 | + /> |
| 31 | + {{- else }} |
| 32 | + <img |
| 33 | + class="my-0 rounded-md{{ with $nozoom }} nozoom{{ end }}{{ with $class }} {{ . }}{{ end }}" |
| 34 | + srcset=" |
| 35 | + {{ (.Resize "330x").RelPermalink }} 330w, |
| 36 | + {{ (.Resize "660x").RelPermalink }} 660w, |
| 37 | + {{ (.Resize "1024x").RelPermalink }} 1024w, |
| 38 | + {{ (.Resize "1320x").RelPermalink }} 2x" |
| 39 | + src="{{ (.Resize "660x").RelPermalink }}" |
| 40 | + data-zoom-src="{{ (.Resize "1320x").RelPermalink }}" |
| 41 | + alt="{{ $altText }}" |
| 42 | + /> |
| 43 | + {{- end }} |
| 44 | + {{- else }} |
| 45 | + <img class="my-0 rounded-md{{ with $nozoom }} nozoom{{ end }}{{ with $class }} {{ . }}{{ end }}" src="{{ $url.String }}" alt="{{ $altText }}" /> |
| 46 | + {{- end }} |
| 47 | + {{- end }} |
| 48 | + {{ with $caption }}<figcaption>{{ . | markdownify }}</figcaption>{{ end }} |
| 49 | + {{ if $href }}</a>{{ end }} |
| 50 | + </figure> |
| 51 | +{{- end -}} |
0 commit comments