-
Notifications
You must be signed in to change notification settings - Fork 0
/
render-image.html
40 lines (35 loc) · 1.22 KB
/
render-image.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
{{- $url := urls.Parse .Destination -}}
{{/* https://github.com/gohugoio/hugo/pull/10666/files */}}
{{- $params := $url.Query -}}
{{- $lazyParam := $params.Get "lazy" -}}
{{- $lazy := false -}}
{{- if ne $lazyParam "false" -}}
{{- $lazy = $lazyParam | default .Page.Site.Params.pictureLazy -}}
{{- end -}}
{{- $webpParam := $params.Get "webp" -}}
{{- $webp := false -}}
{{- if ne $webpParam "false" -}}
{{- $webp = $webpParam | default .Page.Site.Params.pictureWebp -}}
{{- end -}}
{{- $lqipParam := $params.Get "lqip" -}}
{{- $lqip := false -}}
{{- if ne $lqipParam "false" -}}
{{- $lqip = $lqipParam | default .Page.Site.Params.pictureLqip -}}
{{- end -}}
{{- $file := $url.Path}}
{{- $img := .Page.Resources.GetMatch $file -}}
{{- if and (not $img) .Page.File -}}
{{ $path := path.Join .Page.File.Dir $file }}
{{- $img = resources.Get $path -}}
{{- end -}}
{{- with $img -}}
{{ partial "picture.html" (dict "img" . "alt" $.Text "lazy" $lazy "webp" $webp "lqip" $lqip) }}
{{- else -}}
{{ if $lazy }}
{{/* do not use lazy without dimensions */}}
{{ warnf "Can't use lazy images for %s" .Destination }}
{{ end }}
<picture>
<img src="{{ .Destination | safeURL }}" alt="{{ $.Text }}" />
</picture>
{{- end -}}