Embed html templates for deployment
This commit is contained in:
parent
f0ace114b0
commit
0a74bd8345
1 changed files with 16 additions and 1 deletions
17
html.go
17
html.go
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue