website/layouts/partials/helpers/icons.html
2023-01-12 23:07:45 +01:00

9 lines
No EOL
398 B
HTML

{{ $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! */}}