Embed html templates for deployment

This commit is contained in:
Eli Ribble 2025-11-11 17:47:27 +00:00
parent f0ace114b0
commit 0a74bd8345
No known key found for this signature in database

17
html.go
View file

@ -3,6 +3,7 @@ package main
import (
"bytes"
"context"
"embed"
"errors"
"fmt"
"html/template"
@ -19,6 +20,9 @@ import (
"github.com/stephenafamo/bob/dialect/psql/sm"
)
//go:embed templates/*
var embeddedFiles embed.FS
var (
dashboard = newBuiltTemplate("dashboard", "authenticated")
oauthPrompt = newBuiltTemplate("oauth-prompt", "authenticated")
@ -345,7 +349,18 @@ func newBuiltTemplate(name string, files ...string) BuiltTemplate {
}
func parseEmbedded(files []string) *template.Template {
return nil
funcMap := makeFuncMap()
// Remap the file names to embedded paths
paths := make([]string, 0)
for _, f := range files {
paths = append(paths, "templates/"+f+".html")
}
for _, f := range components {
paths = append(paths, "templates/components/"+f+".html")
}
name := files[0]
return template.Must(
template.New(name).Funcs(funcMap).ParseFS(embeddedFiles, paths...))
}
func parseFromDisk(files []string) (*template.Template, error) {