Skip to content

Commit de28182

Browse files
committed
fallback to original image if smaller images do not exist
1 parent 74d51fe commit de28182

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

_includes/downloads/board_image.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{% for static_file in site.static_files %}
2+
{% assign small_image = "/assets/images/boards/small/" | append: include.board_image %}
3+
{% if static_file.path == small_image %}
4+
{% assign has_responsive_images = true %}
5+
{% endif %}
6+
{% endfor %}
7+
{% if has_responsive_images %}
8+
<img srcset="{{ small_image | relative_url }} 300w,
9+
{{ "/assets/images/boards/large/" | append: include.board_image | relative_url }} 700w"
10+
sizes="(max-width: 1024px) 700px,
11+
300px"
12+
src="{{ "/assets/images/boards/original/" | append: include.board_image | relative_url }}" alt="Image of Board">
13+
{% else %}
14+
<img src="{{ "/assets/images/boards/original/" | append: include.board_image | relative_url }}" alt="Image of Board">
15+
{% endif %}

_layouts/download.html

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,17 @@ <h3>by {{ page.manufacturer }}</h3>
88
<div class="download-section">
99
<div class="details">
1010
<div class="section">
11-
<img src="{{ "/assets/images/boards/large/" | append: page.board_image | relative_url }}" alt="Image of Board">
11+
{% for static_file in site.static_files %}
12+
{% assign large_image = "/assets/images/boards/large/" | append: page.board_image %}
13+
{% if static_file.path == large_image %}
14+
{% assign has_responsive_images = true %}
15+
{% endif %}
16+
{% endfor %}
17+
{% if has_responsive_images %}
18+
<img src="{{ large_image | relative_url }}" alt="Image of Board">
19+
{% else %}
20+
<img src="{{ "/assets/images/boards/original/" | append: page.board_image | relative_url }}" alt="Image of Board">
21+
{% endif %}
1222
<p>
1323
{{ content }}
1424
</p>

blinka.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ <h1>Blinka</h1>
6161
{{ "/assets/images/boards/large/" | append: board.board_image | relative_url }} 700w"
6262
sizes="(max-width: 1024px) 700px,
6363
300px"
64-
src="{{ "/assets/images/boards/original" | append: info.board_image | relative_url }}" alt="Image of Board">
64+
src="{{ "/assets/images/boards/original/" | append: info.board_image | relative_url }}" alt="Image of Board">
6565
</div>
6666
<div class="details">
6767
<h3>{{ board.name }}</h3>

downloads.html

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,7 @@ <h1>Downloads</h1>
7272
<a href="{{ info.url | relative_url }}">
7373
<div>
7474
<div class="img-responsive-4by3">
75-
<img srcset="{{ "/assets/images/boards/small/" | append: info.board_image | relative_url }} 300w,
76-
{{ "/assets/images/boards/large/" | append: info.board_image | relative_url }} 700w"
77-
sizes="(max-width: 1024px) 700px,
78-
300px"
79-
src="{{ "/assets/images/boards/original" | append: info.board_image | relative_url }}" alt="Image of Board">
75+
{% include downloads/board_image.html board_image=info.board_image %}
8076
</div>
8177
<div class="details">
8278
<h3>{{ info.name | default: board.id }}</h3>
@@ -102,11 +98,7 @@ <h3>{{ info.name | default: board.id }}</h3>
10298
<a href="{{ board.url | relative_url }}">
10399
<div>
104100
<div class="img-responsive-4by3">
105-
<img srcset="{{ "/assets/images/boards/small/" | append: board.board_image | relative_url }} 300w,
106-
{{ "/assets/images/boards/large/" | append: board.board_image | relative_url }} 700w"
107-
sizes="(max-width: 1024px) 700px,
108-
300px"
109-
src="{{ "/assets/images/boards/original" | append: board.board_image | relative_url }}" alt="Image of Board">
101+
{% include downloads/board_image.html board_image=board.board_image %}
110102
</div>
111103
<div class="details">
112104
<h3>{{ board.name }}</h3>

0 commit comments

Comments
 (0)