Skip to content

Instantly share code, notes, and snippets.

@jbasoo
Last active December 7, 2023 12:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbasoo/08fa237b6df11bf1233c141e22eba67b to your computer and use it in GitHub Desktop.
Save jbasoo/08fa237b6df11bf1233c141e22eba67b to your computer and use it in GitHub Desktop.
Convert SVG files to a Shopify Liquid Snippet
#!/bin/bash
# USAGE: svg-to-liquid.sh iconSourcePath icons.liquid
# Add the icons.liquid file to your theme snippets then output the icon using {% render 'icons', icon: 'icon-name' %}
echo "Converting SVGs to Shopify Liquid Snippet"
liquid=$'{% case icon %}\n';
for svg in $1/*.svg; do
file="$(basename $svg)";
name="${file%.*}"
liquid+=" {% when '"${name}"' %}"$'\n'
liquid+=" $(cat $svg)"
liquid+=$'\n'
done
liquid+="{% endcase %}";
echo "${liquid}" > $2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment