diff options
Diffstat (limited to 'pages/create.go')
| -rw-r--r-- | pages/create.go | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/pages/create.go b/pages/create.go index 5469ee8..f16d2d8 100644 --- a/pages/create.go +++ b/pages/create.go @@ -2,10 +2,13 @@ package pages import ( "delayed.link/storage" + "embed" _ "embed" "html/template" + "io/fs" "net/http" "net/url" + "path/filepath" "strconv" "strings" "time" @@ -83,17 +86,17 @@ func Create(w http.ResponseWriter, r *http.Request) { } } -//go:embed create.gohtml -var recContent string - -//go:embed style.gohtml -var style string - -//go:embed header.gohtml -var header string +//go:embed html +var pages embed.FS func init() { - template.Must(tmpl.Parse(style)) - template.Must(tmpl.Parse(header)) - template.Must(tmpl.New("create").Parse(recContent)) + entries, _ := pages.ReadDir("html") + for _, entry := range entries { + name := entry.Name() + if !entry.IsDir() && strings.HasSuffix(name, ".gohtml") { + tmplName := strings.SplitN(name, ".", 2)[0] + content, _ := fs.ReadFile(pages, filepath.Join("html", name)) + template.Must(tmpl.New(tmplName).Parse(string(content))) + } + } } |
