mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2025-07-19 23:35:31 -04:00
create inline-svg partial function
[skip ci]
This commit is contained in:
15
layouts/partials/functions/inline-svg.html
Normal file
15
layouts/partials/functions/inline-svg.html
Normal file
@@ -0,0 +1,15 @@
|
||||
{{ $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 */}}
|
||||
{{ printf "<!-- auto-inlined from: %s -->" $svg.Permalink | safeHTML }}
|
||||
{{ $html | safeHTML -}}
|
Reference in New Issue
Block a user