2022-05-24 18:30:14 +04:00
|
|
|
package web
|
|
|
|
|
|
|
|
import (
|
|
|
|
"dwelling-radio/pkg/logging"
|
|
|
|
"embed"
|
|
|
|
"html/template"
|
2022-05-24 19:42:47 +04:00
|
|
|
"io/fs"
|
2022-05-24 18:30:14 +04:00
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/Joker/jade"
|
|
|
|
)
|
|
|
|
|
|
|
|
//go:embed assets
|
|
|
|
var assetsDir embed.FS
|
|
|
|
|
|
|
|
func Assets() http.FileSystem {
|
2022-05-24 19:42:47 +04:00
|
|
|
f, _ := fs.Sub(assetsDir, "assets")
|
|
|
|
return http.FS(f)
|
2022-05-24 18:30:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func AssetsGetFile(path string) ([]byte, error) {
|
2022-05-24 19:42:47 +04:00
|
|
|
return assetsDir.ReadFile("assets/" + path)
|
2022-05-24 18:30:14 +04:00
|
|
|
}
|
|
|
|
|
2022-05-24 19:42:47 +04:00
|
|
|
//go:embed templates/index.jade
|
|
|
|
var indexJadeTpl []byte
|
|
|
|
var IndexTemplate *template.Template
|
2022-05-24 18:30:14 +04:00
|
|
|
|
|
|
|
func CompileTemplates(lErr *logging.Logger) {
|
2022-05-24 19:42:47 +04:00
|
|
|
indexParsedTpl, err := jade.Parse("index", indexJadeTpl)
|
2022-05-24 18:30:14 +04:00
|
|
|
if err != nil {
|
|
|
|
lErr.Fatalln(err)
|
|
|
|
}
|
|
|
|
|
2022-05-24 19:42:47 +04:00
|
|
|
IndexTemplate, err = template.New("index").Parse(indexParsedTpl)
|
2022-05-24 18:30:14 +04:00
|
|
|
if err != nil {
|
|
|
|
lErr.Fatalln(err)
|
|
|
|
}
|
|
|
|
}
|