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