fix embeding issue and sqlite db new database string

This commit is contained in:
ghostersk
2026-03-08 06:51:04 +00:00
parent 97e07689a9
commit 964a345657
4 changed files with 15 additions and 11 deletions

View File

@@ -4,9 +4,11 @@ import (
"bytes"
"fmt"
"html/template"
"io/fs"
"log"
"net/http"
"path/filepath"
"github.com/ghostersk/gowebmail"
)
// Renderer holds one compiled *template.Template per page name.
@@ -16,11 +18,6 @@ type Renderer struct {
templates map[string]*template.Template
}
const (
tmplBase = "web/templates/base.html"
tmplDir = "web/templates"
)
// NewRenderer parses every page template paired with the base layout.
// Call once at startup; fails fast if any template has a syntax error.
func NewRenderer() (*Renderer, error) {
@@ -30,19 +27,23 @@ func NewRenderer() (*Renderer, error) {
"mfa.html",
"admin.html",
}
templateFS, err := fs.Sub(gowebmail.WebFS, "web/templates")
if err != nil {
log.Fatalf("embed templates fs: %v", err)
}
r := &Renderer{templates: make(map[string]*template.Template, len(pages))}
for _, page := range pages {
pagePath := filepath.Join(tmplDir, page)
// New instance per page — base FIRST, then the page file.
// This means the page's {{define}} blocks override the base's {{block}} defaults
// without any other page's definitions being present in the same pool.
t, err := template.New("base").ParseFiles(tmplBase, pagePath)
t, err := template.ParseFS(templateFS, "base.html", page)
if err != nil {
return nil, fmt.Errorf("renderer: parse %s: %w", page, err)
}
name := page[:len(page)-5] // strip ".html"
name := page[:len(page)-5]
r.templates[name] = t
log.Printf("renderer: loaded template %q", name)
}