HUGE refactor. working towards web UI
This commit is contained in:
parent
dd54e8cc49
commit
1f94eecca9
29 changed files with 1669 additions and 162 deletions
59
templates/html.go
Normal file
59
templates/html.go
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
package templates
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"html/template"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
//go:embed "html/layout.html"
|
||||
var layoutHTML string
|
||||
//go:embed "html/index.html"
|
||||
var indexHTML string
|
||||
//go:embed "html/vod-list.html"
|
||||
var vodListHTML string
|
||||
//go:embed "html/vod.html"
|
||||
var vodHTML string
|
||||
|
||||
type (
|
||||
Crumb struct {
|
||||
Name string
|
||||
Path string
|
||||
}
|
||||
)
|
||||
|
||||
var templateFuncs = template.FuncMap{
|
||||
"FormatTime": func (time time.Time, format string) string {
|
||||
return time.Format(format)
|
||||
},
|
||||
"ToLower": func (str string) string {
|
||||
return strings.ToLower(str)
|
||||
},
|
||||
"ToUpper": func (str string) string {
|
||||
return strings.ToUpper(str)
|
||||
},
|
||||
"Crumbs": func (path string) []Crumb {
|
||||
split := strings.Split(strings.TrimSuffix(path, "/"), "/")
|
||||
crumbs := make([]Crumb, len(split))
|
||||
for i := range crumbs {
|
||||
segment := split[i]
|
||||
crumbs[i] = Crumb{
|
||||
segment,
|
||||
strings.Repeat("../", len(crumbs)-i-1),
|
||||
}
|
||||
}
|
||||
return crumbs
|
||||
},
|
||||
}
|
||||
|
||||
var BaseTemplate = template.Must(template.New("base").Funcs(templateFuncs).Parse(
|
||||
strings.Join([]string{
|
||||
layoutHTML,
|
||||
// headerHTML,
|
||||
// footerHTML,
|
||||
}, "\n"),
|
||||
))
|
||||
var IndexTemplate = template.Must(template.Must(BaseTemplate.Clone()).Parse(indexHTML))
|
||||
var VODListTemplate = template.Must(template.Must(BaseTemplate.Clone()).Parse(vodListHTML))
|
||||
var VODTemplate = template.Must(template.Must(BaseTemplate.Clone()).Parse(vodHTML))
|
||||
Loading…
Add table
Add a link
Reference in a new issue