Template is being embed directly and all code for directory was removed.
This commit is contained in:
parent
74ae6f4213
commit
f2d5b5e8c5
25
web/web.go
25
web/web.go
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user