mirror of
https://github.com/Theodor-Springmann-Stiftung/kgpz_web.git
synced 2025-10-29 09:05:30 +00:00
exp akteure
This commit is contained in:
@@ -4,6 +4,8 @@ import (
|
||||
"html/template"
|
||||
"io"
|
||||
"io/fs"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
@@ -14,6 +16,8 @@ var embed_cache sync.Map
|
||||
func EmbedSafe(fs fs.FS) func(string) template.HTML {
|
||||
embed_cache.Clear()
|
||||
return func(path string) template.HTML {
|
||||
path = strings.TrimSpace(path)
|
||||
path = filepath.Clean(path)
|
||||
val, err := getFileData(fs, path)
|
||||
if err != nil {
|
||||
return template.HTML("")
|
||||
@@ -26,6 +30,8 @@ func EmbedSafe(fs fs.FS) func(string) template.HTML {
|
||||
func Embed(fs fs.FS) func(string) string {
|
||||
embed_cache.Clear()
|
||||
return func(path string) string {
|
||||
path = strings.TrimSpace(path)
|
||||
path = filepath.Clean(path)
|
||||
val, err := getFileData(fs, path)
|
||||
if err != nil {
|
||||
return ""
|
||||
@@ -54,3 +60,27 @@ func getFileData(fs fs.FS, path string) ([]byte, error) {
|
||||
embed_cache.Store(path, data)
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func EmbedXSLT(fs fs.FS) func(string) template.HTML {
|
||||
embed_cache.Clear()
|
||||
return func(path string) template.HTML {
|
||||
path = strings.TrimSpace(path)
|
||||
path = filepath.Clean(path)
|
||||
fn := filepath.Base(path)
|
||||
ext := filepath.Ext(fn)
|
||||
fn = fn[:len(fn)-len(ext)]
|
||||
|
||||
if (ext != ".xsl" && ext != ".xslt") || ext == "" || fn == "" {
|
||||
return template.HTML("[ERROR: " + "file is not an XSLT file" + "]")
|
||||
}
|
||||
|
||||
val, err := getFileData(fs, path)
|
||||
if err != nil {
|
||||
return template.HTML("[ERROR: " + err.Error() + "]")
|
||||
}
|
||||
|
||||
src := "<script id=\"" + fn + "\" type=\"application/xml\">\n" + string(val) + "\n</script>"
|
||||
|
||||
return template.HTML(src)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user