2023-08-12 23:27:11 -04:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
|
|
|
"embed"
|
|
|
|
"encoding/json"
|
|
|
|
"html/template"
|
|
|
|
"net/url"
|
|
|
|
|
|
|
|
"github.com/htfy96/reformism"
|
|
|
|
"go.fifitido.net/ytdl-web/pkg/view/html"
|
|
|
|
"go.fifitido.net/ytdl-web/ytdl/metadata"
|
|
|
|
)
|
|
|
|
|
|
|
|
//go:embed views/*
|
|
|
|
var viewsfs embed.FS
|
|
|
|
|
2023-08-14 18:14:08 -04:00
|
|
|
var Views = html.New(
|
2023-08-12 23:27:11 -04:00
|
|
|
viewsfs,
|
|
|
|
html.DefaultOptions().
|
|
|
|
WithBaseDir("views").
|
|
|
|
WithFunction("unsafe", func(s string) template.HTML {
|
|
|
|
return template.HTML(s)
|
|
|
|
}).
|
|
|
|
WithFunction("queryEscape", func(s string) string {
|
|
|
|
return url.QueryEscape(s)
|
|
|
|
}).
|
|
|
|
WithFunction("jsonMarshal", func(s any) (string, error) {
|
|
|
|
j, err := json.MarshalIndent(s, "", " ")
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return string(j), nil
|
|
|
|
}).
|
|
|
|
WithFunction("downloadContext", func(meta metadata.Metadata, url, basePath string, format metadata.Format) map[string]any {
|
|
|
|
return map[string]any{
|
|
|
|
"Meta": meta,
|
|
|
|
"Url": url,
|
|
|
|
"BasePath": basePath,
|
|
|
|
"Format": format,
|
|
|
|
}
|
|
|
|
}).
|
|
|
|
WithFunctions(reformism.FuncsHTML),
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2023-08-14 18:14:08 -04:00
|
|
|
if err := Views.Load(); err != nil {
|
2023-08-12 23:27:11 -04:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|