-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathimg.html
More file actions
50 lines (39 loc) · 1.79 KB
/
img.html
File metadata and controls
50 lines (39 loc) · 1.79 KB
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
41
42
43
44
45
46
47
48
49
50
{{/* prettier-ignore-start */}}
{{- /* The img shortcode creates <img> tags proxied through imageproxy.
Site parameters:
params:
imageproxy:
url: "http://proxy.example.com/" # absolute URL of imageproxy instance
default_baseurl: "http://example.com/" # optional baseurl configured on imageproxy
always_sign: false # always sign proxied image URLs
always_b64: false # always base64 encode proxied image URLs
Shortcode usage:
{{<img src="image.jpg" options="300x200,r90" class="right">}}
If the imageproxy.always_sign parameter or the "sign" attribute on the shortcode is true,
the image URL will be signed with the key in the IMAGEPROXY_SIGNATUREKEY environment variable.
Options must be in their canonical form for signing to work.
{{< img src="https://external/image.jpg" sign="true" >}}
See more details on imageproxy at https://github.com/willnorris/imageproxy
*/ -}}
{{/* prettier-ignore-end */}}
{{- $src := .Get "src" }}
{{- with $.Page.Resources.GetMatch (.Get "src") }}
{{- $src = .Permalink }}
{{- end }}
{{- $options := .Get "options" | default "x" }}
{{- if eq $options "x" }}
{{- with (.Get "width" | default "0") }}
{{- $options = printf "%d%s" (mul (int .) 2) $options }}
{{- end }}
{{- with (.Get "height" | default "0") }}
{{- $options = printf "%s%d" $options (mul (int .) 2) }}
{{- end }}
{{- end }}
{{- $sign := (or .Page.Site.Params.imageproxy.always_sign (.Get "sign")) }}
{{- $b64 := (or .Page.Site.Params.imageproxy.always_b64 (.Get "b64")) }}
<img
src="{{ partial "imageproxy-url" (slice $src $options $sign $b64) }}"
{{- with .Get "alt" }}alt="{{ . }}"{{ end }}
{{- with .Get "class" }}class="{{ . }}"{{ end }}
{{- with .Get "width" }}width="{{ . }}"{{ end }}
{{- with .Get "height" }}height="{{ . }}"{{ end -}} />