package view import ( "crypto/sha256" "embed" "encoding/hex" "html/template" "io/fs" "net/http" "github.com/eugenioenko/autentico/pkg/config" "github.com/eugenioenko/autentico/pkg/cspnonce" ) //go:embed *.html static/* var FS embed.FS // ParseTemplate parses layout.html together with the named page template, // returning a template set where executing "layout" renders the full page. func ParseTemplate(name string) (*template.Template, error) { tmpl := template.New("layout").Funcs(template.FuncMap{ "authURL": func(path string) string { return config.GetBootstrap().AppOAuthPath + path }, "hasThemeCss": func() bool { return config.Get().ThemeCssResolved != "" }, "footerLinks": func() []config.FooterLink { return config.Get().FooterLinks }, "brandColor": func() string { return config.Get().Theme.BrandColor }, "logoURL": func(v any) template.URL { raw, _ := v.(string) if raw == "" || config.ValidateLogoURL(raw) != nil { return template.URL(config.GetBootstrap().AppOAuthPath + "/static/logo.svg") } return template.URL(raw) }, }) return tmpl.ParseFS(FS, "layout.html", name+".html") } // InjectNonce reads the CSP nonce from the request context and adds it to the // template data map under the key "CspNonce". Call this before ExecuteTemplate // so that templates can render nonce="{{.CspNonce}}" on