summaryrefslogtreecommitdiffstats
path: root/internal/admin/server.go
diff options
context:
space:
mode:
authorivar <i@oiee.no>2026-04-03 14:46:05 +0200
committerivar <i@oiee.no>2026-04-03 14:46:05 +0200
commita46309ac64261814d931f538fad373ea8a4f0e95 (patch)
tree6aeb1333071e433fc9e3bc7779b8b41d9e270544 /internal/admin/server.go
parenta21fa502891a6d2f0600485b1b76762ecc178fd0 (diff)
downloadnebbet.no-a46309ac64261814d931f538fad373ea8a4f0e95.tar.xz
nebbet.no-a46309ac64261814d931f538fad373ea8a4f0e95.zip
feat: embed admin templates into binary with //go:embed
Move admin templates from templates/admin/*.html to internal/admin/templates/*.html and embed them using //go:embed directive. This removes the runtime dependency on having template files on disk, allowing the templates to be compiled into the binary. Changes: - Add embed import and //go:embed directive for templates - Change ParseGlob() to ParseFS() to load from embedded filesystem - Copy templates to internal/admin/templates/ for embedding Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Diffstat (limited to 'internal/admin/server.go')
-rw-r--r--internal/admin/server.go10
1 files changed, 7 insertions, 3 deletions
diff --git a/internal/admin/server.go b/internal/admin/server.go
index 33413ee..b36c598 100644
--- a/internal/admin/server.go
+++ b/internal/admin/server.go
@@ -4,6 +4,7 @@
package admin
import (
+ "embed"
"fmt"
"html/template"
"net/http"
@@ -19,6 +20,9 @@ import (
"nebbet.no/internal/builder"
)
+//go:embed templates/*.html
+var adminTemplates embed.FS
+
// Server is an http.Handler that serves the admin post-management UI.
type Server struct {
// PostsDir is the directory where post markdown files are stored,
@@ -353,7 +357,7 @@ func slugify(title string) string {
return s
}
-// mustParseTemplates loads admin templates from the templates/admin/ directory.
+// mustParseTemplates loads admin templates from the embedded filesystem.
func mustParseTemplates() *template.Template {
funcs := template.FuncMap{
"splitTags": func(s string) []string {
@@ -367,8 +371,8 @@ func mustParseTemplates() *template.Template {
return tags
},
}
- // Load all .html files from templates/admin/ directory
- tmpl, err := template.New("admin").Funcs(funcs).ParseGlob("templates/admin/*.html")
+ // Parse templates from embedded filesystem
+ tmpl, err := template.New("admin").Funcs(funcs).ParseFS(adminTemplates, "templates/*.html")
if err != nil {
panic(fmt.Sprintf("failed to parse admin templates: %v", err))
}