frontend: Rework asset generation
This commit reworks frontend asset generation to not need manually written html files, but instead generate them automatically.
This commit is contained in:
parent
ebdbe9fabd
commit
ccab2883a6
42 changed files with 408 additions and 177 deletions
|
|
@ -6,10 +6,8 @@ import (
|
|||
"embed"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/component"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/fsx"
|
||||
"github.com/tkw1536/goprogram/stream"
|
||||
)
|
||||
|
||||
|
|
@ -21,21 +19,16 @@ func (*Static) Name() string { return "static" }
|
|||
|
||||
func (*Static) Routes() []string { return []string{"/static/"} }
|
||||
|
||||
//go:embed dist
|
||||
var staticFS embed.FS
|
||||
|
||||
func (static *Static) Handler(route string, context context.Context, io stream.IOStream) (http.Handler, error) {
|
||||
fs, err := fs.Sub(distStaticFS, "dist")
|
||||
// take the filesystem
|
||||
fs, err := fs.Sub(staticFS, "dist")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// censor *.html in the filesystem
|
||||
fs = fsx.Censor(fs, func(path string) bool {
|
||||
suffix := "html"
|
||||
return len(path) >= len(suffix) && strings.EqualFold(path[len(path)-len(suffix):], suffix)
|
||||
})
|
||||
|
||||
// and serve it
|
||||
return http.StripPrefix(route, http.FileServer(http.FS(fs))), nil
|
||||
}
|
||||
|
||||
//go:embed dist
|
||||
var distStaticFS embed.FS
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue