Export xsl into seperate file via embedding

This commit is contained in:
Simon Martens
2024-12-28 10:53:17 +01:00
parent 58df7cc1cb
commit 579ce63ee2
8 changed files with 152 additions and 73 deletions

25
functions/embedding.go Normal file
View File

@@ -0,0 +1,25 @@
package functions
import (
"html/template"
"io"
"io/fs"
)
// TODO: this needs to be cached, FS reads are expensive
func EmbedSafe(fs fs.FS) func(string) template.HTML {
return func(path string) template.HTML {
f, err := fs.Open(path)
if err != nil {
return ""
}
defer f.Close()
data, err := io.ReadAll(f)
if err != nil {
return ""
}
return template.HTML(data)
}
}