/
_@image.hbs
63 lines (63 loc) · 2.52 KB
/
_@image.hbs
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
51
52
53
54
55
56
57
58
59
60
61
62
63
{{!--
Create custom image tag
@author zkreations
@param {image} src - Image url
@param {string} [alt=data:messages.image] - Fallback text
@param {string} [id] - Unique id
@param {string} [class] - Additional classes
@param {string} [width] - Image width
@param {string} [height] - Image height
@param {number} [resize] - Change dimensions
@param {string} [ratio] - Aspect ratio
@param {string} [sizes] - Sizes attribute value
@param {array} [srcset] - Array of dimensions
@param {string} [loading] - Loading attribute
@param {string} [params] - Additional Google image parameters
--}}
<b:includable id='@image'>
<b:if cond='data:src'>
{{!-- Check if image is hosted on Blogger --}}
<b:with value='data:src.isYoutube
? data:src.youtubeMaxResDefaultUrl
: data:src' var='source'>
<b:with value='(data:resize
? resizeImage(data:source, data:resize, data:ratio)
: (data:source))' var='image'>
<b:tag expr:alt='data:alt ?: data:messages.image' name='img'>
{{!-- Close tag --}}
<b:attr name='b:whitespace' value='remove'/>
{{!-- Id and class --}}
<b:attr name='id' expr:value='data:id'/>
<b:class cond='data:class' expr:name='data:class'/>
{{!-- Width and height --}}
<b:attr name='width' expr:value='data:width ?: data:image.width'/>
<b:attr name='height' expr:value='data:height ?: data:image.height'/>
{{!-- Sizes attribute --}}
<b:attr name='sizes' expr:value='data:sizes'/>
{{!-- Loading attribute --}}
<b:attr name='loading' expr:value='data:loading'/>
{{!-- Check if image is hosted on Google for additional parameters --}}
<b:with value='[
"content.com/img/a/",
"content.com/blogger_img_proxy"
]' var='servers'>
<b:with value='data:params and (data:servers any (server => server in data:image))
? ("-" + data:params)
: ""' var='params'>
{{!-- If srcset exists, generate the src attribute --}}
<b:attr name='src' expr:value='(data:srcset
? resizeImage(data:image, data:srcset.first, data:ratio)
: data:image) + data:params'/>
</b:with>
</b:with>
{{!-- If srcset exists, generate the srcset attribute --}}
<b:if cond='data:srcset'>
<b:attr name='srcset' expr:value='sourceSet(data:image, data:srcset, data:ratio)'/>
</b:if>
</b:tag>
</b:with>
</b:with>
<b:else/>
<b:comment render='true'>Parameter [src] is required.</b:comment>
</b:if>
</b:includable>