1
0

Template is being embed directly and all code for directory was removed.

This commit is contained in:
Alexander Andreev 2022-05-24 19:42:47 +04:00
parent 74ae6f4213
commit f2d5b5e8c5
Signed by: Arav
GPG Key ID: 0388CC8FAA51063F

View File

@ -4,43 +4,36 @@ import (
"dwelling-radio/pkg/logging"
"embed"
"html/template"
"io/fs"
"net/http"
"github.com/Joker/jade"
)
var compiledTemplates map[string]*template.Template
//go:embed assets
var assetsDir embed.FS
func Assets() http.FileSystem {
return http.FS(assetsDir)
f, _ := fs.Sub(assetsDir, "assets")
return http.FS(f)
}
func AssetsGetFile(path string) ([]byte, error) {
return assetsDir.ReadFile(path)
return assetsDir.ReadFile("assets/" + path)
}
//go:embed templates
var templatesDir embed.FS
func Template(name string) *template.Template {
return compiledTemplates[name]
}
//go:embed templates/index.jade
var indexJadeTpl []byte
var IndexTemplate *template.Template
func CompileTemplates(lErr *logging.Logger) {
compiledTemplates = make(map[string]*template.Template)
indexStr, err := jade.ParseFileFromFileSystem("index.jade", http.FS(templatesDir))
indexParsedTpl, err := jade.Parse("index", indexJadeTpl)
if err != nil {
lErr.Fatalln(err)
}
indexTpl, err := template.New("index").Parse(indexStr)
IndexTemplate, err = template.New("index").Parse(indexParsedTpl)
if err != nil {
lErr.Fatalln(err)
}
compiledTemplates["index"] = indexTpl
}