2024-04-24 00:34:57 +00:00
|
|
|
package frontend
|
|
|
|
|
|
|
|
import (
|
|
|
|
"embed"
|
2024-11-24 01:01:50 +00:00
|
|
|
"fmt"
|
2024-04-24 00:34:57 +00:00
|
|
|
"html/template"
|
|
|
|
"io/fs"
|
2024-11-24 01:01:50 +00:00
|
|
|
|
|
|
|
"git.janky.solutions/finn/lockserver/config"
|
2024-04-24 00:34:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
//go:embed static
|
|
|
|
static embed.FS
|
|
|
|
Static fs.FS
|
|
|
|
|
|
|
|
//go:embed *.html
|
|
|
|
templatesFS embed.FS
|
|
|
|
Templates *template.Template
|
2024-04-25 19:06:20 +00:00
|
|
|
|
|
|
|
funcs = template.FuncMap{
|
2024-11-24 01:01:50 +00:00
|
|
|
"version": func() string { return fmt.Sprintf("better-zwave-locks %s", config.Version) },
|
2024-04-25 19:06:20 +00:00
|
|
|
}
|
2024-04-24 00:34:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2024-04-25 19:06:20 +00:00
|
|
|
t := template.New("").Funcs(funcs)
|
|
|
|
|
2024-04-24 00:34:57 +00:00
|
|
|
var err error
|
2024-04-25 19:06:20 +00:00
|
|
|
Templates, err = t.ParseFS(templatesFS, "*")
|
2024-04-24 00:34:57 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
Static, err = fs.Sub(static, "static")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|