Add icons helper

This commit is contained in:
Vri 🌈 2023-01-12 23:07:45 +01:00
parent ebe608f8c9
commit 2d7954c1d1
Signed by: vrifox
GPG key ID: D40098E5B60B2197
3 changed files with 16 additions and 1 deletions

View file

@ -0,0 +1,5 @@
.icon {
width: 2rem;
height: 2rem;
fill: currentColor;
}

View file

@ -1 +1,2 @@
@import "verticalposts";
@import "verticalposts";
@import "icons";

View file

@ -0,0 +1,9 @@
{{ $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! */}}