embed fs
parent
e6f551913a
commit
a0ddc7f25f
|
|
@ -9,8 +9,17 @@ import (
|
||||||
"slices"
|
"slices"
|
||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"embed"
|
||||||
|
_ "embed"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:embed testdata/index.tmpl
|
||||||
|
var embeddedIndexTMPL string
|
||||||
|
|
||||||
|
//go:embed testdata/*
|
||||||
|
var embeddedDir embed.FS
|
||||||
|
|
||||||
var dir = func() string {
|
var dir = func() string {
|
||||||
if v := os.Getenv("UI_D"); v != "" {
|
if v := os.Getenv("UI_D"); v != "" {
|
||||||
return v
|
return v
|
||||||
|
|
@ -19,10 +28,11 @@ var dir = func() string {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
func (h Handler) ui(w http.ResponseWriter, r *http.Request) error {
|
func (h Handler) ui(w http.ResponseWriter, r *http.Request) error {
|
||||||
fs := http.FileServer(http.Dir(dir))
|
if path.Base(r.URL.Path) == "ui" || r.URL.Path == "/" {
|
||||||
if path.Base(r.URL.Path) == "ui" {
|
|
||||||
return h.uiIndex(w, r)
|
return h.uiIndex(w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fs := http.FileServer(http.FS(embeddedDir))
|
||||||
http.StripPrefix("/experimental/ui", fs).ServeHTTP(w, r)
|
http.StripPrefix("/experimental/ui", fs).ServeHTTP(w, r)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -47,6 +57,9 @@ func (h Handler) uiIndex(w http.ResponseWriter, r *http.Request) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
b, _ := os.ReadFile(path.Join(dir, "index.tmpl"))
|
b, _ := os.ReadFile(path.Join(dir, "index.tmpl"))
|
||||||
|
if len(b) == 0 {
|
||||||
|
b = []byte(embeddedIndexTMPL)
|
||||||
|
}
|
||||||
|
|
||||||
tmpl := template.New(r.URL.Path).Funcs(template.FuncMap{
|
tmpl := template.New(r.URL.Path).Funcs(template.FuncMap{
|
||||||
"feeds": func() []feeds.Feed {
|
"feeds": func() []feeds.Feed {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue