about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--frontend/dev.go9
-rw-r--r--frontend/embedded.go8
-rw-r--r--internal/server/server.go6
-rw-r--r--internal/server/templates.go11
4 files changed, 25 insertions, 9 deletions
diff --git a/frontend/dev.go b/frontend/dev.go
new file mode 100644
index 0000000..6cde8a5
--- /dev/null
+++ b/frontend/dev.go
@@ -0,0 +1,9 @@
+//go:build !embed
+
+package frontend
+
+import (
+	"os"
+)
+
+var Files = os.DirFS("frontend/")
diff --git a/frontend/embedded.go b/frontend/embedded.go
new file mode 100644
index 0000000..5310d65
--- /dev/null
+++ b/frontend/embedded.go
@@ -0,0 +1,8 @@
+//go:build embed
+
+package frontend
+
+import "embed"
+
+//go:embed *
+var Files embed.FS
diff --git a/internal/server/server.go b/internal/server/server.go
index a9df405..0474e39 100644
--- a/internal/server/server.go
+++ b/internal/server/server.go
@@ -16,6 +16,7 @@ import (
 	"strconv"
 	"time"
 
+	"searchix/frontend"
 	cfg "searchix/internal/config"
 	"searchix/internal/importer"
 	"searchix/internal/options"
@@ -243,10 +244,7 @@ func New(runtimeConfig *Config) (*Server, error) {
 		}
 	})
 
-	mux.Handle(
-		"/static/",
-		http.StripPrefix("/static/", http.FileServer(http.Dir("frontend/static"))),
-	)
+	mux.Handle("/static/", http.FileServer(http.FS(frontend.Files)))
 
 	if runtimeConfig.LiveReload {
 		applyDevModeOverrides(config)
diff --git a/internal/server/templates.go b/internal/server/templates.go
index 17b14ba..bd3ad90 100644
--- a/internal/server/templates.go
+++ b/internal/server/templates.go
@@ -4,9 +4,10 @@ import (
 	"fmt"
 	"html"
 	"html/template"
+	"io/fs"
 	"log/slog"
 	"path"
-	"path/filepath"
+	"searchix/frontend"
 	"searchix/internal/options"
 	"strings"
 
@@ -50,13 +51,13 @@ func loadTemplate(layoutFile string, filename string) (*template.Template, error
 	tpl := template.New("index.gotmpl")
 
 	tpl.Funcs(templateFuncs)
-	_, err := tpl.ParseFiles(layoutFile)
+	_, err := tpl.ParseFS(frontend.Files, layoutFile)
 	if err != nil {
 		return nil, errors.WithMessage(err, "could not parse layout template")
 	}
 
 	if filename != "" {
-		_, err = tpl.ParseGlob(filename)
+		_, err = tpl.ParseFS(frontend.Files, filename)
 		if err != nil {
 			return nil, errors.WithMessage(err, "could not parse template")
 		}
@@ -66,7 +67,7 @@ func loadTemplate(layoutFile string, filename string) (*template.Template, error
 }
 
 func loadTemplates() (TemplateCollection, error) {
-	templateDir := path.Join("frontend", "templates")
+	templateDir := "templates"
 	templates := make(TemplateCollection, 0)
 
 	layoutFile := path.Join(templateDir, "index.gotmpl")
@@ -78,7 +79,7 @@ func loadTemplates() (TemplateCollection, error) {
 	templates["index"] = index
 
 	glob := path.Join(templateDir, "blocks", "*.gotmpl")
-	templatePaths, err := filepath.Glob(glob)
+	templatePaths, err := fs.Glob(frontend.Files, glob)
 	if err != nil {
 		return nil, errors.WithMessage(err, "could not glob block templates")
 	}