Skip to content

Commit 41baf83

Browse files
adityatelangehank
authored and
hank
committed
Use new 'Image render hook' template from Hugo. (adityatelange#1526)
* Pull render-image template from Hugo https://github.com/gohugoio/hugo/commits/master/tpl/tplimpl/embedded/templates/_default/_markup/render-image.html cloned at b893a09aa62c01a62e32b0effdb02e86b51d46d6 * Add loading=lazy attribute adityatelange@c353447
1 parent b78aa8c commit 41baf83

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed
+22-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,22 @@
1-
<img loading="lazy" src="{{ .Destination | safeURL }}" alt="{{ .Text }}" {{ with .Title}} title="{{ . }}" {{ end }} />
1+
{{- $u := urls.Parse .Destination -}}
2+
{{- $src := $u.String -}}
3+
{{- if not $u.IsAbs -}}
4+
{{- $path := strings.TrimPrefix "./" $u.Path }}
5+
{{- with or (.PageInner.Resources.Get $path) (resources.Get $path) -}}
6+
{{- $src = .RelPermalink -}}
7+
{{- with $u.RawQuery -}}
8+
{{- $src = printf "%s?%s" $src . -}}
9+
{{- end -}}
10+
{{- with $u.Fragment -}}
11+
{{- $src = printf "%s#%s" $src . -}}
12+
{{- end -}}
13+
{{- end -}}
14+
{{- end -}}
15+
{{- $attributes := merge .Attributes (dict "alt" .Text "src" $src "title" (.Title | transform.HTMLEscape) "loading" "lazy") -}}
16+
<img
17+
{{- range $k, $v := $attributes -}}
18+
{{- if $v -}}
19+
{{- printf " %s=%q" $k $v | safeHTMLAttr -}}
20+
{{- end -}}
21+
{{- end -}}>
22+
{{- /**/ -}}

0 commit comments

Comments
 (0)