From 58a02be5cf0f13156c42d82fbb212b509e614e01 Mon Sep 17 00:00:00 2001 From: Prad Nukala Date: Wed, 9 Oct 2024 14:15:05 -0400 Subject: [PATCH] feat: nebula assets served from CDN --- Makefile | 25 ++++++------ cmd/hway/server.go | 2 + devbox.json | 10 ++--- pkg/idpvr/search.go | 1 - pkg/idpvr/txns.go | 1 - pkg/nebula/assets/scripts.templ | 8 ++-- pkg/nebula/assets/scripts_templ.go | 16 ++++---- pkg/nebula/global/styles/layout.templ | 8 ++-- pkg/nebula/global/styles/layout_templ.go | 48 ++++++++++-------------- 9 files changed, 54 insertions(+), 65 deletions(-) delete mode 100644 pkg/idpvr/search.go delete mode 100644 pkg/idpvr/txns.go diff --git a/Makefile b/Makefile index acb6da371..2121e69dd 100644 --- a/Makefile +++ b/Makefile @@ -313,7 +313,17 @@ gen-pkl: .PHONY: motr-build hway-build nebula-build nebula-copy -hway-build: nebula-build nebula-copy gen-templ +nebula-build: + @echo "(nebula) Building nebula" + cd pkg/nebula && bun install && bun run build + @echo "(nebula) Copying assets to hway" + cp -r pkg/nebula/assets/js pkg/nebula/assets/css cmd/hway/build + +motr-build: gen-templ gen-pkl + @echo "(dwn) Building motr.wasm -> Service Worker IPFS Vault" + GOOS=js GOARCH=wasm go build -o ./pkg/dwn/app.wasm ./cmd/motr/main.go + +hway-build: nebula-build gen-templ @echo "(motr) Building Highway gateway" GOOS=js GOARCH=wasm go build -o ./cmd/hway/build/app.wasm ./cmd/hway/server.go @@ -321,19 +331,6 @@ hway-dev: @echo "(motr) Deploying Highway gateway" cd cmd/hway && bun run dev -motr-build: gen-templ gen-pkl - @echo "(dwn) Building motr.wasm -> Service Worker IPFS Vault" - GOOS=js GOARCH=wasm go build -o ./pkg/dwn/app.wasm ./cmd/motr/main.go - -nebula-build: - @echo "(nebula) Building nebula" - cd pkg/nebula && bun install && bun run build - -nebula-copy: - @echo "(nebula) Copying assets to hway" - cp -r pkg/nebula/assets/js pkg/nebula/assets/css cmd/hway/build - - ############################################################################### ### help ### ############################################################################### diff --git a/cmd/hway/server.go b/cmd/hway/server.go index fbba40d65..f220f8cd7 100644 --- a/cmd/hway/server.go +++ b/cmd/hway/server.go @@ -5,6 +5,7 @@ package main import ( "github.com/labstack/echo/v4" "github.com/onsonr/sonr/internal/ctx" + "github.com/onsonr/sonr/pkg/nebula" "github.com/onsonr/sonr/pkg/nebula/routes" "github.com/syumai/workers" ) @@ -12,6 +13,7 @@ import ( func main() { s := echo.New() s.Use(ctx.UseSession) + nebula.UseAssets(s) s.GET("/", routes.Home) s.GET("/login", routes.LoginStart) s.GET("/register", routes.RegisterStart) diff --git a/devbox.json b/devbox.json index 60d8509e4..0dfaeaefd 100644 --- a/devbox.json +++ b/devbox.json @@ -32,11 +32,11 @@ "shell": { "scripts": { "build:docker": ["make local-image"], - "build:hway": ["make build-nebula", "make build-hway"], - "build:nebula": ["make build-nebula"], - "build:motr": ["make build-motr"], - "build:sonrd": ["make build-motr", "make build"], - "build": ["make build-motr", "make build", "make build-hway"], + "build:hway": ["make hway-build"], + "build:nebula": ["make nebula-build"], + "build:motr": ["make motr-build"], + "build:sonrd": ["make motr-build", "make build"], + "build": ["make motr-build", "make build", "make hway-build"], "gen:proto": ["rm -rf ./pkg/nebula/node_modules", "make proto-gen"], "gen:pkl": ["make gen-pkl"], "gen:templ": ["make gen-templ"], diff --git a/pkg/idpvr/search.go b/pkg/idpvr/search.go deleted file mode 100644 index 96400f5c1..000000000 --- a/pkg/idpvr/search.go +++ /dev/null @@ -1 +0,0 @@ -package idpvr diff --git a/pkg/idpvr/txns.go b/pkg/idpvr/txns.go deleted file mode 100644 index 96400f5c1..000000000 --- a/pkg/idpvr/txns.go +++ /dev/null @@ -1 +0,0 @@ -package idpvr diff --git a/pkg/nebula/assets/scripts.templ b/pkg/nebula/assets/scripts.templ index 7ca023dd7..ba20c1c9b 100644 --- a/pkg/nebula/assets/scripts.templ +++ b/pkg/nebula/assets/scripts.templ @@ -12,17 +12,17 @@ var ( ) templ Styles() { - + } templ Alpine() { - + } templ Dexie() { - + } templ Htmx() { - + } diff --git a/pkg/nebula/assets/scripts_templ.go b/pkg/nebula/assets/scripts_templ.go index 07ceda408..e814c58f4 100644 --- a/pkg/nebula/assets/scripts_templ.go +++ b/pkg/nebula/assets/scripts_templ.go @@ -45,9 +45,9 @@ func Styles() templ.Component { return templ_7745c5c3_Err } var templ_7745c5c3_Var2 string - templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs("/css/styles.css") + templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs("https://cdn.sonr.id/css/styles.css") if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/nebula/assets/scripts.templ`, Line: 15, Col: 31} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/nebula/assets/scripts.templ`, Line: 15, Col: 50} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2)) if templ_7745c5c3_Err != nil { @@ -87,9 +87,9 @@ func Alpine() templ.Component { return templ_7745c5c3_Err } var templ_7745c5c3_Var4 string - templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs("/js/alpine.min.js") + templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs("https://cdn.sonr.id/js/alpine.min.js") if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/nebula/assets/scripts.templ`, Line: 19, Col: 34} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/nebula/assets/scripts.templ`, Line: 19, Col: 53} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) if templ_7745c5c3_Err != nil { @@ -129,9 +129,9 @@ func Dexie() templ.Component { return templ_7745c5c3_Err } var templ_7745c5c3_Var6 string - templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs("/js/dexie.min.js") + templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs("https://cdn.sonr.id/js/dexie.min.js") if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/nebula/assets/scripts.templ`, Line: 23, Col: 33} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/nebula/assets/scripts.templ`, Line: 23, Col: 52} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6)) if templ_7745c5c3_Err != nil { @@ -171,9 +171,9 @@ func Htmx() templ.Component { return templ_7745c5c3_Err } var templ_7745c5c3_Var8 string - templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs("/js/htmx.min.js") + templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs("https://cdn.sonr.id/js/htmx.min.js") if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/nebula/assets/scripts.templ`, Line: 27, Col: 32} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/nebula/assets/scripts.templ`, Line: 27, Col: 51} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8)) if templ_7745c5c3_Err != nil { diff --git a/pkg/nebula/global/styles/layout.templ b/pkg/nebula/global/styles/layout.templ index 81603968f..4804d8589 100644 --- a/pkg/nebula/global/styles/layout.templ +++ b/pkg/nebula/global/styles/layout.templ @@ -34,6 +34,8 @@ templ Layout(title string, remote bool) { @cdn.Styles() + @cdn.Htmx() + @cdn.Alpine() @@ -47,8 +49,6 @@ templ Layout(title string, remote bool) {
{ children... }
- @cdn.Alpine() - @cdn.Htmx() } @@ -58,6 +58,8 @@ templ LayoutNoBody(title string, remote bool) { @cdn.Styles() + @cdn.Htmx() + @cdn.Alpine() @@ -72,8 +74,6 @@ templ LayoutNoBody(title string, remote bool) {
{ children... }
- @cdn.Alpine() - @cdn.Htmx() diff --git a/pkg/nebula/global/styles/layout_templ.go b/pkg/nebula/global/styles/layout_templ.go index 206a55502..881fa9130 100644 --- a/pkg/nebula/global/styles/layout_templ.go +++ b/pkg/nebula/global/styles/layout_templ.go @@ -153,6 +153,14 @@ func Layout(title string, remote bool) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } + templ_7745c5c3_Err = cdn.Htmx().Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = cdn.Alpine().Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err @@ -160,7 +168,7 @@ func Layout(title string, remote bool) templ.Component { var templ_7745c5c3_Var5 string templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(title) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/nebula/global/styles/layout.templ`, Line: 40, Col: 17} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/nebula/global/styles/layout.templ`, Line: 42, Col: 17} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5)) if templ_7745c5c3_Err != nil { @@ -174,19 +182,7 @@ func Layout(title string, remote bool) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</main>") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = cdn.Alpine().Render(ctx, templ_7745c5c3_Buffer) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = cdn.Htmx().Render(ctx, templ_7745c5c3_Buffer) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</body></html>") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</main></body></html>") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -223,6 +219,14 @@ func LayoutNoBody(title string, remote bool) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } + templ_7745c5c3_Err = cdn.Htmx().Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = cdn.Alpine().Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<meta charset=\"UTF-8\"><meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><title>") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err @@ -230,7 +234,7 @@ func LayoutNoBody(title string, remote bool) templ.Component { var templ_7745c5c3_Var7 string templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(title) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/nebula/global/styles/layout.templ`, Line: 64, Col: 17} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/nebula/global/styles/layout.templ`, Line: 66, Col: 17} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7)) if templ_7745c5c3_Err != nil { @@ -244,19 +248,7 @@ func LayoutNoBody(title string, remote bool) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div>") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = cdn.Alpine().Render(ctx, templ_7745c5c3_Buffer) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = cdn.Htmx().Render(ctx, templ_7745c5c3_Buffer) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</body></main></html>") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div></body></main></html>") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err }