package site import ( "embed" _ "embed" "fmt" "html/template" "io/fs" "path" "path/filepath" "strings" ) var templates map[string]*template.Template func init() { templates = make(map[string]*template.Template) fs.WalkDir(templateDir, "templates", func(p string, d fs.DirEntry, err error) error { if d.IsDir() || !strings.HasSuffix(p, ".html") { return nil } basePath := strings.TrimSuffix(path.Base(p), filepath.Ext(p)) templates[basePath] = template.Must(template.ParseFS(templateDir, p, "templates/_layout.html.tmpl")) return nil }) fmt.Println("Parsed templates") for k, ts := range templates { fmt.Printf("%s: ", k) for _, t := range ts.Templates() { fmt.Printf("%s ", t.Name()) } fmt.Println() } fmt.Println() } //go:embed templates/* var templateDir embed.FS //go:embed static/* var staticContent embed.FS