|
19 | 19 | {{- $options := .options | default dict -}}
|
20 | 20 | {{- $params := (merge $context $options) -}}
|
21 | 21 | {{- $mime_type := $params.mime_type -}}
|
22 |
| -{{- $title := $params.title -}} |
23 |
| -{{- $url := $params.url -}} |
24 |
| -{{- $width := $params.width -}} |
25 |
| -{{- $height := $params.height -}} |
26 |
| -{{- $derivatives := $params.derivatives -}} |
27 |
| -{{- $alt := (or $params.alt $params.description) | default "" -}} |
28 | 22 | {{- $class_name := $params.class_name -}}
|
29 |
| -{{- $decoding := $params.decoding | default "async" -}} |
30 |
| -{{- $loading := cond (eq $params.lazy true) "lazy" ($params.loading | default false) -}} |
31 |
| -{{- $ratio := $params.ratio -}} |
32 |
| -{{- $sizes := $params.sizes -}} |
33 |
| -{{- $preload := $params.preload | default false -}} |
34 | 23 |
|
35 |
| -{{- $image_attributes := partialCached "utils/html/attribute" (dict |
36 |
| - "loading" $loading |
37 |
| - "decoding" $decoding |
38 |
| -) $params -}} |
39 | 24 | {{- if in $mime_type "image" -}}
|
40 |
| - <picture{{ with $class_name }} class="{{- . -}}"{{ end }}> |
41 |
| - {{- with $derivatives -}} |
42 |
| - {{- $data := (index $derivatives "original") -}} |
43 |
| - {{- with $ratio -}} |
44 |
| - {{- $data = (or (index $derivatives $ratio) (index $derivatives "original")) -}} |
45 |
| - {{- end -}} |
46 |
| - {{- with $data -}} |
47 |
| - {{- $srcsets := .srcsets -}} |
48 |
| - {{- $local_sizes := (or $sizes .sizes) -}} |
49 |
| - {{- $src := .src -}} |
50 |
| - {{- $width := .width -}} |
51 |
| - {{- $height := .height -}} |
52 |
| - {{- range $srcsets -}} |
53 |
| - {{ $srcset := .srcset | default "" }} |
54 |
| - {{ $type := .type | default ""}} |
55 |
| - <source sizes="{{- $local_sizes -}}" srcset="{{- $srcset -}}" type="{{- $type -}}"> |
56 |
| - {{- $preload_attr := (dict |
57 |
| - "as" "image" |
58 |
| - "imagesizes" $local_sizes |
59 |
| - "imagesrcset" $srcset |
60 |
| - "type" $type |
61 |
| - ) -}} |
62 |
| - {{- if and $preload (eq $type "image/avif") (not (in ($globals.Scratch.Get "preload") $preload_attr)) -}} |
63 |
| - {{- $globals.Scratch.Add "preload" (slice $preload_attr) -}} |
64 |
| - {{- end -}} |
65 |
| - {{- end -}} |
66 |
| - <img src="{{- $src -}}" width="{{- $width -}}" height="{{- $height -}}" {{ $image_attributes }} alt="{{- $alt -}}"{{ with $params.preload }} fetchpriority="high"{{ end }}> |
67 |
| - {{- end -}} |
68 |
| - {{- else -}} |
69 |
| - {{- with $url -}} |
70 |
| - {{- $src := $params.src | default (cond (hasPrefix . "//") (print "https:" .) .) -}} |
71 |
| - <img src="{{- $src -}}" width="{{- $width -}}" height="{{- $height -}}" {{ $image_attributes }} alt="{{- $alt -}}"{{ with $params.preload }} fetchpriority="high"{{ end }}> |
72 |
| - {{- $preload_attr := (dict |
73 |
| - "as" "image" |
74 |
| - "href" $src |
75 |
| - "type" $mime_type |
76 |
| - ) -}} |
77 |
| - {{- if and $preload (not (in ($globals.Scratch.Get "preload") $preload_attr)) -}} |
78 |
| - {{- $globals.Scratch.Add "preload" (slice $preload_attr) -}} |
79 |
| - {{- end -}} |
80 |
| - {{- end -}} |
81 |
| - {{- end -}} |
| 25 | + <picture {{- with $class_name }} class="{{- . -}}"{{ end }}> |
| 26 | + {{- partialCached "utils/asset/image/sources" (dict |
| 27 | + "globals" $globals |
| 28 | + "context" $params |
| 29 | + ) $params -}} |
| 30 | + {{- partialCached "utils/asset/image/img" (dict |
| 31 | + "globals" $globals |
| 32 | + "context" $params |
| 33 | + ) $params -}} |
82 | 34 | </picture>
|
83 | 35 | {{- end -}}
|
0 commit comments