mirror of
https://github.com/Theodor-Springmann-Stiftung/kgpz_web.git
synced 2025-10-29 00:55:32 +00:00
26 lines
395 B
Go
26 lines
395 B
Go
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)
|
|
}
|
|
}
|