diff options
-rw-r--r-- | default.nix | 1 | ||||
-rw-r--r-- | templates/dev.go | 9 | ||||
-rw-r--r-- | templates/embed.go | 8 | ||||
-rw-r--r-- | templates/page.templ | 4 |
4 files changed, 20 insertions, 2 deletions
diff --git a/default.nix b/default.nix index e3a47f7..d135453 100644 --- a/default.nix +++ b/default.nix @@ -116,6 +116,7 @@ rec { ${pkgs.templ}/bin/templ generate ''; subPackages = [ "cmd/server" ]; + tags = [ "embed" ]; ldflags = [ "-s" "-w" diff --git a/templates/dev.go b/templates/dev.go new file mode 100644 index 0000000..37a6416 --- /dev/null +++ b/templates/dev.go @@ -0,0 +1,9 @@ +//go:build !embed + +package templates + +import ( + "os" +) + +var Files = os.DirFS("templates/") diff --git a/templates/embed.go b/templates/embed.go new file mode 100644 index 0000000..e7e1f18 --- /dev/null +++ b/templates/embed.go @@ -0,0 +1,8 @@ +//go:build embed + +package templates + +import "embed" + +//go:embed * +var Files embed.FS diff --git a/templates/page.templ b/templates/page.templ index 08c17a0..1667fb0 100644 --- a/templates/page.templ +++ b/templates/page.templ @@ -1,7 +1,7 @@ package templates import ( - "os" + "io/fs" "net/url" "website/internal/config" @@ -12,7 +12,7 @@ var ( ) func init() { - bytes, err := os.ReadFile("templates/style.css") + bytes, err := fs.ReadFile(Files, "style.css") if err != nil { panic(err) } |