blob: df1397658427f5102153b9e0905e4bc35e75a44c (
plain)
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
|
{% assign name_dot_format = include.file | split: "." %}
{% assign name = name_dot_format | first %}
{% assign format = name_dot_format | last %}
{% assign version = include.version | default: "1" %}
{% comment %} Let 'suffix' = last 4 chars of 'name', 'prefix' = the rest {% endcomment %}
{% assign suffix = name | slice: -4, 4 %}
{% assign rname = name | split: "" | reverse | join: "" %}
{% assign rsuffix = suffix | split: "" | reverse | join: "" %}
{% assign rprefix = rname | remove_first: rsuffix %}
{% assign prefix = rprefix | split: "" | reverse | join: "" %}
{% comment %} If 'name' ends in "full", half-size image must exist {% endcomment %}
{% assign name_full = name %}
{% if suffix == "full" %}
{% assign name_half = prefix | append: "half" %}
{% else %}
{% assign name_half = name_full %}
{% endif %}
{% comment %} Insert the image, linking to the full-size version {% endcomment %}
{% if include.class %}
{% assign add_class = 'class="' | append: include.class | append: '"' %}
{% endif %}
{% if include.style or include.width %}
{% assign set_width = "width:" | append: include.width %}
{% assign set_style = include.style | default: set_width %}
{% assign add_style = 'style="' | append: set_style | append: '"' %}
{% endif %}
<p>
<a href="{{ name_full }}.{{ format }}?v={{ version }}">
<picture>
<source srcset="{{ name_half }}.avif?v={{ version }}" type="image/avif">
{% if name_full == name_half %}
<img src="{{ name_half }}.{{ format }}?v={{ version }}" {{ add_class }} {{ add_style }}
alt="{{ include.alt }}" title="{{ include.alt }}">
{% else %}
<source srcset="{{ name_half }}.webp?v={{ version }}" type="image/webp">
<img src="{{ name_half }}.jpg?v={{ version }}" {{ add_class }} {{ add_style }}
alt="{{ include.alt }}" title="{{ include.alt }}">
{% endif %}
</picture>
</a>
</p>
|