Compare commits
2 Commits
e6f551913a
...
8f0c62bd77
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8f0c62bd77 | ||
|
|
a0ddc7f25f |
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user