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"
|
"dwelling-radio/pkg/logging"
|
||||||
"embed"
|
"embed"
|
||||||
"html/template"
|
"html/template"
|
||||||
|
"io/fs"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/Joker/jade"
|
"github.com/Joker/jade"
|
||||||
)
|
)
|
||||||
|
|
||||||
var compiledTemplates map[string]*template.Template
|
|
||||||
|
|
||||||
//go:embed assets
|
//go:embed assets
|
||||||
var assetsDir embed.FS
|
var assetsDir embed.FS
|
||||||
|
|
||||||
func Assets() http.FileSystem {
|
func Assets() http.FileSystem {
|
||||||
return http.FS(assetsDir)
|
f, _ := fs.Sub(assetsDir, "assets")
|
||||||
|
return http.FS(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
func AssetsGetFile(path string) ([]byte, error) {
|
func AssetsGetFile(path string) ([]byte, error) {
|
||||||
return assetsDir.ReadFile(path)
|
return assetsDir.ReadFile("assets/" + path)
|
||||||
}
|
}
|
||||||
|
|
||||||
//go:embed templates
|
//go:embed templates/index.jade
|
||||||
var templatesDir embed.FS
|
var indexJadeTpl []byte
|
||||||
|
var IndexTemplate *template.Template
|
||||||
func Template(name string) *template.Template {
|
|
||||||
return compiledTemplates[name]
|
|
||||||
}
|
|
||||||
|
|
||||||
func CompileTemplates(lErr *logging.Logger) {
|
func CompileTemplates(lErr *logging.Logger) {
|
||||||
compiledTemplates = make(map[string]*template.Template)
|
indexParsedTpl, err := jade.Parse("index", indexJadeTpl)
|
||||||
|
|
||||||
indexStr, err := jade.ParseFileFromFileSystem("index.jade", http.FS(templatesDir))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
lErr.Fatalln(err)
|
lErr.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
indexTpl, err := template.New("index").Parse(indexStr)
|
IndexTemplate, err = template.New("index").Parse(indexParsedTpl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
lErr.Fatalln(err)
|
lErr.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
compiledTemplates["index"] = indexTpl
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user