Compare commits

..

2 Commits

Author SHA1 Message Date
bel
8f0c62bd77 runs 2025-05-07 22:27:06 -06:00
bel
a0ddc7f25f embed fs 2025-05-07 22:15:01 -06:00

View File

@@ -2,15 +2,26 @@ package handler
import (
"encoding/json"
"fmt"
"net/http"
"os"
"path"
"show-rss/src/feeds"
"slices"
"strings"
"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,11 +30,13 @@ 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)
}
http.StripPrefix("/experimental/ui", fs).ServeHTTP(w, r)
fs := http.FileServer(http.FS(embeddedDir))
r.URL.Path = fmt.Sprintf("/testdata/%s", strings.TrimPrefix(r.URL.Path, "/experimental/ui"))
fs.ServeHTTP(w, r)
return nil
}
@@ -47,6 +60,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 {