Created
June 7, 2024 21:51
-
-
Save seandogg/382a397abf2e719bf1787b090c4bdfb5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{%- comment -%} | |
Parameters | |
img_url: {string} Shopify image_url of the image including a width parameter eg. &width={width} | |
max_width: {number} maximum width used for srcset (optional) | |
{%- endcomment -%} | |
{%- liquid | |
assign widths = '160,320,480,640,800,960,1120,1280,1440,1600,1920,2240,2560' | split: ',' | |
assign max_width_num = max_width | plus: 0 | |
capture srcset_output | |
for width in widths | |
assign width_num = width | plus: 0 | |
if max_width_num > 0 and max_width_num < width_num | |
break | |
endif | |
unless forloop.first | |
echo ', ' | |
endunless | |
echo img_url | replace: '{width}', width | append: ' ' | append: width | append: 'w' | |
endfor | |
endcapture | |
echo srcset_output | |
-%} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment