1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-04-27 05:38:26 -04:00
jarv.is/layouts/partials/functions/inline-svg.html

17 lines
715 B
HTML

{{- $svg := resources.Get .src -}}
{{- $html := $svg.Content -}}
{{/* remove unneeded tags/attributes when SVG is inlined versus a .svg file */}}
{{- $html = replaceRE "<\\?xml.+\\?>" "" $html -}}
{{- $html = replaceRE " version=\"(.*?)\"" "" $html -}}
{{- $html = replaceRE " xmlns=\"(.*?)\"" "" $html -}}
{{- $wxh := printf "<svg width=\"%d\" height=\"%d\" " .width .height }}
{{- $html = replace $html "<svg " $wxh -}}
{{/* bit of a hack: calling .Permalink so that the SVG file is published too, comment will be removed when minified */}}
{{/* https://gohugo.io/hugo-pipes/introduction/#asset-publishing */}}
{{- printf "<!-- auto-inlined from: %s -->" $svg.Permalink | safeHTML }}
{{- $html | safeHTML -}}