package newtmpl import ( "embed" "fmt" "github.com/bouncepaw/mycorrhiza/internal/cfg" "github.com/bouncepaw/mycorrhiza/util" viewutil2 "github.com/bouncepaw/mycorrhiza/web/viewutil" "html/template" "strings" ) //go:embed *.html var fs embed.FS var base = template.Must(template.ParseFS(fs, "base.html")) type Page struct { TemplateEnglish *template.Template TemplateRussian *template.Template } func NewPage(fs embed.FS, russianTranslation map[string]string, tmpls ...string) *Page { must := template.Must en := must(must(must( base.Clone()). Funcs(template.FuncMap{ "beautifulName": util.BeautifulName, "inc": func(i int) int { return i + 1 }, }). Parse(fmt.Sprintf(` {{define "wiki name"}}%s{{end}} {{define "user hypha"}}%s{{end}} `, cfg.WikiName, cfg.UserHypha))). ParseFS(fs, tmpls...)) if cfg.UseAuth { en = must(en.Parse(` {{define "auth"}}
{{end}} `)) } if cfg.AllowRegistration { must(en.Parse(`{{define "registration"}} {{if .Meta.U.Group | eq "anon"}}