{{ $svg := . }}
{{ $class := print $svg "-icon" }}
{{ $match := "<svg (.*)?>(.*)</svg>" }}

{{ $replaceWith := printf `<svg class="%s icon" ${1}>${2}</svg>` $class }}
{{ return (replaceRE $match $replaceWith (printf "/assets/icons/%s.svg" $svg | readFile) | safeHTML) }}

{{/* Taken from https://bitbanged.com/posts/how-to-use-inline-svgs-with-hugo/ */}}
{{/* Only works if SVG is on one line! */}}