41 lines
702 B
Go
41 lines
702 B
Go
package frontend
|
|
|
|
import (
|
|
"embed"
|
|
"fmt"
|
|
"html/template"
|
|
"io/fs"
|
|
"time"
|
|
|
|
"git.janky.solutions/finn/lockserver/config"
|
|
)
|
|
|
|
var (
|
|
//go:embed static
|
|
static embed.FS
|
|
Static fs.FS
|
|
|
|
//go:embed *.html
|
|
templatesFS embed.FS
|
|
Templates *template.Template
|
|
|
|
funcs = template.FuncMap{
|
|
"version": func() string { return fmt.Sprintf("better-zwave-locks %s", config.Version) },
|
|
"time_since": func(t time.Time) string { return time.Since(t).Round(time.Second).String() },
|
|
}
|
|
)
|
|
|
|
func init() {
|
|
t := template.New("").Funcs(funcs)
|
|
|
|
var err error
|
|
Templates, err = t.ParseFS(templatesFS, "*")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
Static, err = fs.Sub(static, "static")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|