Skip to content

Commit d27f9b7

Browse files
authored
Merge pull request #187 from sus-admin/main
squashed commit
2 parents cf9b2f9 + 68b8fb5 commit d27f9b7

File tree

4 files changed

+646
-0
lines changed

4 files changed

+646
-0
lines changed

_includes/figure.liquid

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{% assign img_path = include.path | remove: '.jpg' | remove: '.jpeg' | remove: '.png' | remove: '.tiff' | remove: '.gif' %}
2+
{% assign parts = include.path | split: '.' %}
3+
{% assign ext = parts.last %}
4+
5+
<figure
6+
{% if include.slot %}
7+
slot="{{ include.slot }}"
8+
{% endif %}
9+
>
10+
<picture>
11+
<!-- Auto scaling with imagemagick -->
12+
<!--
13+
See https://www.debugbear.com/blog/responsive-images#w-descriptors-and-the-sizes-attribute and
14+
https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images for info on defining 'sizes' for responsive images
15+
-->
16+
{% if site.imagemagick.enabled %}
17+
<source
18+
class="responsive-img-srcset"
19+
{% if ext == '.jpg' or ext == '.jpeg' or ext == '.png' or ext == '.tiff' or ext == '.gif' %}
20+
srcset="{% for i in site.imagemagick.widths %}{{ img_path | relative_url }}-{{ i }}.webp {{i}}w,{% endfor %}"
21+
type="image/webp"
22+
{% else %}
23+
srcset="{{ include.path | relative_url }}"
24+
{% endif %}
25+
{% if include.sizes %}
26+
sizes="{{include.sizes}}"
27+
{% else %}
28+
sizes="95vw"
29+
{% endif %}
30+
>
31+
{% endif %}
32+
<img
33+
src="{% if include.url %}{{ include.url }}{% elsif include.cache_bust %}{{ include.path | relative_url | bust_file_cache }}{% else %}{{ include.path | relative_url }}{% endif %}"
34+
{% if include.class %}
35+
class="{{ include.class }}"
36+
{% endif %}
37+
{% if include.width %}
38+
width="{{ include.width }}"
39+
{% else %}
40+
width="100%"
41+
{% endif %}
42+
{% if include.height %}
43+
height="{{ include.height }}"
44+
{% else %}
45+
height="auto"
46+
{% endif %}
47+
{% if include['min-width'] or include['min-height'] or include['max-width'] or include['max-height'] %}
48+
style="
49+
{% if include['min-width'] %}
50+
min-width: {{ include.min-width }};
51+
{% endif %}
52+
{% if include['min-height'] %}
53+
min-height: {{ include.min-height }};
54+
{% endif %}
55+
{% if include['max-width'] %}
56+
max-width: {{ include.max-width }};
57+
{% endif %}
58+
{% if include['max-height'] %}
59+
max-height: {{ include.max-height }};
60+
{% endif %}
61+
"
62+
{% endif %}
63+
{% if include.alt %}
64+
alt="{{ include.alt }}"
65+
{% endif %}
66+
{% if include.title %}
67+
title="{{ include.title }}"
68+
{% endif %}
69+
{% if include.zoomable %}
70+
data-zoomable
71+
{% endif %}
72+
{% if include.loading %}
73+
loading="{{ include.loading }}"
74+
{% elsif site.lazy_loading_images %}
75+
loading="lazy"
76+
{% endif %}
77+
onerror="this.onerror=null; $('.responsive-img-srcset').remove();"
78+
>
79+
</picture>
80+
81+
{% if include.caption %}
82+
<figcaption class="caption">{{ include.caption }}</figcaption>
83+
{% endif %}
84+
</figure>

0 commit comments

Comments
 (0)