Skip to content

Commit

Permalink
Fixed .webp src creation for svg and other files (alshedivat#2698)
Browse files Browse the repository at this point in the history
Added a default srcset in case extension is other than the following:
- .jpg
- .jpeg
- .png
- .tiff
- .gif

fixed alshedivat#2660
  • Loading branch information
KingHowler authored Sep 13, 2024
1 parent 8e9cf03 commit 0465459
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions _includes/figure.liquid
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{% assign img_path = include.path | remove: '.jpg' | remove: '.jpeg' | remove: '.png' | remove: '.tiff' | remove: '.gif' %}
{% assign parts = include.path | split: '.' %}
{% assign ext = parts.last %}

<figure
{% if include.slot %}
Expand All @@ -14,13 +16,17 @@
{% if site.imagemagick.enabled %}
<source
class="responsive-img-srcset"
srcset="{% for i in site.imagemagick.widths %}{{ img_path | relative_url }}-{{ i }}.webp {{i}}w,{% endfor %}"
{% if ext == '.jpg' or ext == '.jpeg' or ext == '.png' or ext == '.tiff' or ext == '.gif' %}
srcset="{% for i in site.imagemagick.widths %}{{ img_path | relative_url }}-{{ i }}.webp {{i}}w,{% endfor %}"
type="image/webp"
{% else %}
srcset="{{ include.path | relative_url }}"
{% endif %}
{% if include.sizes %}
sizes="{{include.sizes}}"
{% else %}
sizes="95vw"
{% endif %}
type="image/webp"
>
{% endif %}
<img
Expand Down

0 comments on commit 0465459

Please sign in to comment.