|
30 | 30 | {% endif %} |
31 | 31 |
|
32 | 32 | <!-- Change the icon of checkbox --> |
| 33 | + |
33 | 34 | {% if _content contains '<input type="checkbox"' %} |
34 | 35 | {% assign _content = _content |
35 | 36 | | replace: '<input type="checkbox" class="task-list-item-checkbox" disabled="disabled" checked="checked" />', |
|
39 | 40 | %} |
40 | 41 | {% endif %} |
41 | 42 |
|
42 | | -<!-- images --> |
| 43 | +<!-- Handle images --> |
| 44 | + |
43 | 45 | {% assign IMG_TAG = '<img ' %} |
44 | 46 |
|
45 | 47 | {% if _content contains IMG_TAG %} |
|
79 | 81 | {% assign _left = _left | remove: ' /' | replace: ' w=', ' width=' | replace: ' h=', ' height=' %} |
80 | 82 | {% assign _attrs = _left | split: '" ' %} |
81 | 83 |
|
82 | | - {% assign _width = null %} |
83 | | - {% assign _height = null %} |
84 | 84 | {% assign _lqip = null %} |
85 | 85 | {% assign _class = null %} |
86 | 86 |
|
|
94 | 94 | {% capture _value %}{{ _pair | last | remove: '"' }}{% endcapture %} |
95 | 95 |
|
96 | 96 | {% case _key %} |
97 | | - {% when 'width' %} |
98 | | - {% assign _width = _value %} |
99 | | - {% when 'height' %} |
100 | | - {% assign _height = _value %} |
101 | 97 | {% when 'src' %} |
102 | 98 | {% assign _src = _value %} |
103 | 99 | {% when 'lqip' %} |
|
114 | 110 | {% endif %} |
115 | 111 |
|
116 | 112 | {% assign _final_src = null %} |
| 113 | + {% assign _lazyload = true %} |
117 | 114 |
|
118 | 115 | {% unless _src contains '//' %} |
119 | 116 | {% assign _final_src = _path_prefix | append: _src %} |
120 | | - {% capture _src_from %}"{{ _src }}"{% endcapture %} |
121 | | - {% capture _src_to %}"{{ _final_src }}"{% endcapture %} |
122 | | - {% assign _left = _left | replace: _src_from, _src_to %} |
| 117 | + {% assign _src_alt = 'src="' | append: _path_prefix %} |
| 118 | + {% assign _left = _left | replace: 'src="', _src_alt %} |
123 | 119 | {% endunless %} |
124 | 120 |
|
125 | 121 | {% if _lqip %} |
126 | | - {% unless _lqip contains ':' %} |
127 | | - {% assign _final_lqip = _path_prefix | append: _lqip %} |
128 | | - {% capture _lqip_from %}"{{ _lqip }}"{% endcapture %} |
129 | | - {% capture _lqip_to %}"{{ _final_lqip }}"{% endcapture %} |
130 | | - {% assign _left = _left | replace: _lqip_from, _lqip_to %} |
131 | | - {% endunless %} |
132 | | - {% endif %} |
| 122 | + {% if _lqip contains ':' %} |
| 123 | + {% assign _lazyload = false %} |
| 124 | + {% else %} |
| 125 | + {% assign _lqip_alt = 'lqip="' | append: _path_prefix %} |
| 126 | + {% assign _left = _left | replace: 'lqip="', _lqip_alt %} |
| 127 | + {% endif %} |
133 | 128 |
|
134 | | - <!-- lazy-load images <https://github.com/aFarkas/lazysizes#readme> --> |
135 | | - {% assign _left = _left | replace: 'src=', 'data-src=' %} |
136 | | - {% if _left contains 'class=' %} |
137 | | - {% assign _left = _left | replace: 'class="', 'class="lazyload ' %} |
138 | | - {% else %} |
139 | | - {% assign _left = _left | append: ' class="lazyload"' %} |
140 | | - {% endif %} |
| 129 | + <!-- add image placeholder --> |
| 130 | + {% assign _left = _left | replace: 'src=', 'data-src=' | replace: ' lqip=', ' data-lqip="true" src=' %} |
141 | 131 |
|
142 | | - <!-- add image placeholder --> |
143 | | - {% if _lqip %} |
144 | | - {% assign _left = _left | replace: ' lqip=', ' data-lqip="true" src=' %} |
145 | 132 | {% else %} |
146 | | - {% if _width and _height %} |
147 | | - <!-- add SVG placehoder --> |
148 | | - {%- capture _svg -%} |
149 | | - src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 {{ _width }} {{ _height }}'%3E%3C/svg%3E" |
150 | | - {%- endcapture -%} |
151 | | - {% assign _left = _svg | append: ' ' | append: _left %} |
152 | | - {% assign _class = _class | append: ' shimmer' %} |
153 | | - {% endif %} |
| 133 | + {% assign _class = _class | append: ' shimmer' %} |
154 | 134 | {% endif %} |
155 | 135 |
|
156 | | - <!-- Bypass the HTML-proofer test --> |
157 | | - {% assign _left = _left | append: ' data-proofer-ignore' %} |
| 136 | + <!-- lazy-load images --> |
| 137 | + {% if _lazyload %} |
| 138 | + {% assign _left = _left | append: ' loading="lazy"' %} |
| 139 | + {% endif %} |
158 | 140 |
|
159 | 141 | {% if page.layout == 'home' %} |
160 | 142 | <!-- create the image wrapper --> |
|
174 | 156 | class="img-link{% unless _lqip %} shimmer{% endunless %}" |
175 | 157 | {% endcapture %} |
176 | 158 | {% assign _img_content = _img_content | slice: 0, _size | append: _class | append: '>' %} |
| 159 | + |
177 | 160 | {% else %} |
178 | 161 | <!-- create the image wrapper --> |
179 | 162 | {% assign _wrapper_start = _final_src |
|
185 | 168 | %} |
186 | 169 |
|
187 | 170 | {% assign _img_content = _img_content | append: _wrapper_start %} |
188 | | - {% assign _right = _right | prepend: '></a' %} |
| 171 | + {% assign _right = '></a' | append: _right %} |
189 | 172 | {% endif %} |
190 | 173 | {% endif %} |
191 | 174 |
|
192 | 175 | <!-- combine --> |
193 | | - {% assign _img_content = _img_content | append: debug | append: IMG_TAG | append: _left | append: _right %} |
| 176 | + {% assign _img_content = _img_content | append: IMG_TAG | append: _left | append: _right %} |
194 | 177 | {% endfor %} |
195 | 178 |
|
196 | 179 | {% if _img_content %} |
|
0 commit comments