lockserver/frontend/frontend.go
Finn f90a7cd66d
All checks were successful
/ build-container (push) Successful in 8m40s
Frontend: put version number in static URL to cache-bust on updates
2025-02-23 14:48:35 -08:00

40 lines
657 B
Go

package frontend
import (
"embed"
"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 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)
}
}