blob: e2052b402265eb0d87939f32105006a70a320557 [file] [log] [blame]
// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"embed"
"path"
"github.com/google/safehtml/template"
)
// Embed the templates and static files into the binary.
// We must use the FS form in order to make them trusted with the
// github.com/google/safehtml/template API.
//go:embed tmpl/*.tmpl
var tmplFS embed.FS
//go:embed static/*
var staticFS embed.FS
const (
// Landing pages
actionLogTmplFile = "actionlog.tmpl"
searchPageTmplFile = "searchpage.tmpl"
overviewPageTmplFile = "overviewpage.tmpl"
rulesPageTmplFile = "rulespage.tmpl"
dbviewPageTmplFile = "dbviewpage.tmpl"
// Common template file
commonTmpl = "common.tmpl"
)
func newTemplate(filename string, funcs template.FuncMap) *template.Template {
if funcs == nil {
funcs = make(template.FuncMap)
}
// Add common functions.
funcs["pages"] = func() []pageID {
return pages
}
funcs["dec"] = func(i int) int {
return i - 1
}
return template.Must(template.New(filename).Funcs(funcs).
ParseFS(template.TrustedFSFromEmbed(tmplFS),
path.Join("tmpl", filename),
path.Join("tmpl", commonTmpl)))
}