Skip to content

Instantly share code, notes, and snippets.

@frankrausch
Last active December 16, 2017 15:35
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frankrausch/107a35fcc2799a868a90101e1d0730af to your computer and use it in GitHub Desktop.
Save frankrausch/107a35fcc2799a868a90101e1d0730af to your computer and use it in GitHub Desktop.
Compile individual SVG icons into one SASS file as data URIs
sourceFiles="../assets/icons/*.svg"
destFile="../assets/sass/_icons.svg.scss"
classPrefix=".icon-"
echo "Compiling icons from "$sourceFiles" into "$destFile" …"
echo "" > $destFile
for fileWithPath in ../assets/icons/*.svg;
do
contents=$(cat $fileWithPath)
contents=$(svgo -s "${contents}")
contents=$(php -r "echo rawurlencode('$contents');")
filename=${fileWithPath##*/}
classname=${filename%.*}
scss=${classPrefix}${classname}"{background-image:url('data:image/svg+xml;utf8,"$contents"')}"
echo $scss >> $destFile
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment