If I want to include the svg in a web page, I can use a shortcode like {{< figure src="triangle.svg" >}} inside my markdown. This will give me a figure that references triangle.svg.
Now, what if I want to embed (inline) the contents of triangle.svg inside the web page?
Been looking for a solution to this but no idea so far.
I created the /svg folder under hugo root to hold the svg’s (since I don’t need them copied over from /static to /public).
Inside markdown I can just call {{< svg "triangle.svg" >}} and the svg is inlined.
Hopefully it’s good enough.
The only lingering question is whether, when I call readFile, there is a way inside the template to remove the first line of the svg in order to prevent the svg’s xml declaration from being embedded.
The typical contents of a standalone triangle.svg might be
I ended up passing in class to a parent element as an easy fix. Obv depends on how you’re planning to use the SVG (semantics dependant), but you could always pass in logic to decide which parent element to use.