From 16603d9f93a3f02b2f49578f6470b6fa3a9db4e3 Mon Sep 17 00:00:00 2001 From: jolheiser Date: Thu, 30 Jan 2025 14:47:56 -0600 Subject: [PATCH] migrate to gomponents Signed-off-by: jolheiser --- README.md | 3 +- flake.lock | 139 +------------------------------ flake.nix | 30 +++---- go.mod | 2 +- go.mod.sri | 2 +- go.sum | 6 +- justfile | 6 -- main.go | 4 +- site.go | 61 ++++++++++++++ site.templ | 36 -------- site_templ.go | 203 --------------------------------------------- tailwind.config.js | 2 +- 12 files changed, 82 insertions(+), 412 deletions(-) delete mode 100644 justfile create mode 100644 site.go delete mode 100644 site.templ delete mode 100644 site_templ.go diff --git a/README.md b/README.md index ade5630..28756d6 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ My [personal website](https://jolheiser.com). -Uses [tailwind](https://tailwindcss.com/) (with [catppuccin btw](https://github.com/catppuccin/tailwindcss)) and [templ](https://github.com/a-h/templ) as a simple static page generator. +Uses [tailwind](https://tailwindcss.com/) (with [catppuccin btw](https://github.com/catppuccin/tailwindcss)) and [gomponents](https://gomponents.com) as a simple static page generator. Links are sourced from [links.jsonnet](links.jsonnet). @@ -18,7 +18,6 @@ If nix isn't available: #### Build Deps - [Go](https://go.dev) -- [templ](https://github.com/a-h/templ) - [tailwind-ctp](https://git.jojodev.com/jolheiser/tailwind-ctp) (TailwindCSS standalone CLI with Catppuccin support) #### Dev Deps diff --git a/flake.lock b/flake.lock index c0ea666..c5bd945 100644 --- a/flake.lock +++ b/flake.lock @@ -18,82 +18,6 @@ "type": "github" } }, - "flake-utils_2": { - "inputs": { - "systems": "systems_2" - }, - "locked": { - "lastModified": 1694529238, - "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "flake-utils_3": { - "locked": { - "lastModified": 1667395993, - "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "gitignore": { - "inputs": { - "nixpkgs": [ - "templ", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1709087332, - "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", - "owner": "hercules-ci", - "repo": "gitignore.nix", - "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", - "type": "github" - }, - "original": { - "owner": "hercules-ci", - "repo": "gitignore.nix", - "type": "github" - } - }, - "gomod2nix": { - "inputs": { - "flake-utils": "flake-utils_2", - "nixpkgs": [ - "templ", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1722589758, - "narHash": "sha256-sbbA8b6Q2vB/t/r1znHawoXLysCyD4L/6n6/RykiSnA=", - "owner": "nix-community", - "repo": "gomod2nix", - "rev": "4e08ca09253ef996bd4c03afa383b23e35fe28a1", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "gomod2nix", - "type": "github" - } - }, "nixpkgs": { "locked": { "lastModified": 1728680019, @@ -114,8 +38,7 @@ "flake-utils": "flake-utils", "nixpkgs": "nixpkgs", "tailwind-ctp": "tailwind-ctp", - "tailwind-ctp-lsp": "tailwind-ctp-lsp", - "templ": "templ" + "tailwind-ctp-lsp": "tailwind-ctp-lsp" } }, "systems": { @@ -133,21 +56,6 @@ "type": "github" } }, - "systems_2": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } - }, "tailwind-ctp": { "inputs": { "nixpkgs": [ @@ -187,51 +95,6 @@ "type": "git", "url": "https://git.jojodev.com/jolheiser/tailwind-ctp-intellisense" } - }, - "templ": { - "inputs": { - "gitignore": "gitignore", - "gomod2nix": "gomod2nix", - "nixpkgs": [ - "nixpkgs" - ], - "xc": "xc" - }, - "locked": { - "lastModified": 1728028863, - "narHash": "sha256-NEkcOnjMN+fI9/Lejy6As3/Cd0rxqU4c4Dwt7OYiiLM=", - "owner": "a-h", - "repo": "templ", - "rev": "318249d145b66fe1d66e34abf2321c86e1dfbc52", - "type": "github" - }, - "original": { - "owner": "a-h", - "repo": "templ", - "type": "github" - } - }, - "xc": { - "inputs": { - "flake-utils": "flake-utils_3", - "nixpkgs": [ - "templ", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1724404748, - "narHash": "sha256-p6rXzNiDm2uBvO1MLzC5pJp/0zRNzj/snBzZI0ce62s=", - "owner": "joerdav", - "repo": "xc", - "rev": "960ff9f109d47a19122cfb015721a76e3a0f23a2", - "type": "github" - }, - "original": { - "owner": "joerdav", - "repo": "xc", - "type": "github" - } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 1d8cd45..880d2f0 100644 --- a/flake.nix +++ b/flake.nix @@ -2,10 +2,6 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs"; flake-utils.url = "github:numtide/flake-utils"; - templ = { - url = "github:a-h/templ"; - inputs.nixpkgs.follows = "nixpkgs"; - }; tailwind-ctp = { url = "git+https://git.jojodev.com/jolheiser/tailwind-ctp"; inputs.nixpkgs.follows = "nixpkgs"; @@ -16,27 +12,28 @@ }; }; - outputs = { - self, - flake-utils, - nixpkgs, - templ, - tailwind-ctp, - tailwind-ctp-lsp, - } @ inputs: + outputs = + { + self, + flake-utils, + nixpkgs, + tailwind-ctp, + tailwind-ctp-lsp, + }@inputs: flake-utils.lib.eachDefaultSystem ( - system: let + system: + let pkgs = nixpkgs.legacyPackages.${system}; tailwind-ctp = inputs.tailwind-ctp.packages.${system}.default; tailwind-ctp-lsp = inputs.tailwind-ctp-lsp.packages.${system}.default; - templ = inputs.templ.packages.${system}.templ; - in { + in + { packages.default = pkgs.buildGoModule { pname = "jolheiser.com"; version = "site"; src = ./.; vendorHash = nixpkgs.lib.fileContents ./go.mod.sri; - nativeBuildInputs = [templ tailwind-ctp]; + nativeBuildInputs = [ tailwind-ctp ]; excludedPackages = "."; postBuild = '' go generate @@ -46,7 +43,6 @@ devShells.default = pkgs.mkShell { nativeBuildInputs = with pkgs; [ go - templ tailwind-ctp tailwind-ctp-lsp vscode-langservers-extracted diff --git a/go.mod b/go.mod index 6fdac75..a7f3123 100644 --- a/go.mod +++ b/go.mod @@ -4,8 +4,8 @@ go 1.21 require ( git.jojodev.com/jolheiser/simpleicons v0.0.3 - github.com/a-h/templ v0.2.778 github.com/google/go-jsonnet v0.20.0 + maragu.dev/gomponents v1.0.0 ) require ( diff --git a/go.mod.sri b/go.mod.sri index ac7c6ef..8989e01 100644 --- a/go.mod.sri +++ b/go.mod.sri @@ -1 +1 @@ -sha256-LCjIObTQdTuKwkM+0DESmaC5gWlbX8rGQkL1hn6Iy8Q= \ No newline at end of file +sha256-e8dPVJnc7J9+9xGo+l1ccCzyF+iqOEGyRhRmdazmgCQ= \ No newline at end of file diff --git a/go.sum b/go.sum index 58ab33e..2e6b0d4 100644 --- a/go.sum +++ b/go.sum @@ -1,9 +1,5 @@ git.jojodev.com/jolheiser/simpleicons v0.0.3 h1:R/UEcl6L6wAScHKu/oYyB0jY62inYes56aM91YlTfqE= git.jojodev.com/jolheiser/simpleicons v0.0.3/go.mod h1:NIhFsYI7rALmUX37teVRzf8BJAv1XtZC1OGeVjmB/No= -github.com/a-h/templ v0.2.778 h1:VzhOuvWECrwOec4790lcLlZpP4Iptt5Q4K9aFxQmtaM= -github.com/a-h/templ v0.2.778/go.mod h1:lq48JXoUvuQrU0VThrK31yFwdRjTCnIE5bcPCM9IP1w= -github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= -github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-jsonnet v0.20.0 h1:WG4TTSARuV7bSm4PMB4ohjxe33IHT5WVTrJSU33uT4g= github.com/google/go-jsonnet v0.20.0/go.mod h1:VbgWF9JX7ztlv770x/TolZNGGFfiHEVx9G6ca2eUmeA= github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= @@ -12,5 +8,7 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo= gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +maragu.dev/gomponents v1.0.0 h1:eeLScjq4PqP1l+r5z/GC+xXZhLHXa6RWUWGW7gSfLh4= +maragu.dev/gomponents v1.0.0/go.mod h1:oEDahza2gZoXDoDHhw8jBNgH+3UR5ni7Ur648HORydM= sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs= sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= diff --git a/justfile b/justfile deleted file mode 100644 index 84524f2..0000000 --- a/justfile +++ /dev/null @@ -1,6 +0,0 @@ -build: - @git add . - @nix build - -generate: - @go generate diff --git a/main.go b/main.go index 05aa439..7301df3 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,6 @@ package main import ( - "context" "encoding/json" "os" @@ -25,7 +24,6 @@ var tailwindCSS = ` @tailwind utilities; ` -//go:generate templ generate //go:generate go run . //go:generate tailwind-ctp -i ./dist/styles.css -o ./dist/styles.css --minify func main() { @@ -52,7 +50,7 @@ func main() { } defer html.Close() - err = index(links.Links).Render(context.Background(), html) + err = index(links.Links).Render(html) if err != nil { panic(err) } diff --git a/site.go b/site.go new file mode 100644 index 0000000..51af0c9 --- /dev/null +++ b/site.go @@ -0,0 +1,61 @@ +package main + +import ( + "fmt" + + g "maragu.dev/gomponents" + c "maragu.dev/gomponents/components" + h "maragu.dev/gomponents/html" +) + +func index(links []Link) g.Node { + return c.HTML5(c.HTML5Props{ + Title: "jolheiser", + Head: []g.Node{ + // title, charset, and viewport are already set by HTML5 + h.Link(h.Rel("shortcut icon"), h.Href("https://www.gravatar.com/avatar/7f4dd86f017ff289cf05a013e22357ef253d1ed6a52bdefca8f965af1080a965?s=16")), + h.Meta(h.Name("author"), h.Content("jolheiser")), + h.Link(h.Rel("stylesheet"), h.Href("styles.css")), + }, + Body: []g.Node{ + h.Class("latte dark:mocha bg-base"), + h.Header(h.Class("relative w-full pt-16 pb-10"), + h.Img(h.Class("mx-auto rounded-full"), h.Alt("avatar"), h.Src("https://www.gravatar.com/avatar/7f4dd86f017ff289cf05a013e22357ef253d1ed6a52bdefca8f965af1080a965?s=125")), + h.P(h.Class("mt-2 text-xl text-center text-lavender"), + g.Text("@jolheiser"), + ), + ), + h.Nav(h.Class("relative max-w-screen-sm mx-auto"), + g.Map(links, func(link Link) g.Node { + return h.A(h.Class("flex relative px-3 py-2 my-6 h-16 text-lg items-center justify-center text-text bg-surface0 cursor-pointer rounded border-solid border-2 border-overlay0 hover:bg-surface2 hover:border-lavender hover:text-blue transition"), h.Title(link.Name), h.Target("_blank"), h.Href(link.URL), + h.SVG(h.Class("absolute left-5 w-10 h-10"), h.Role("img"), ViewBox(0, 0, 24, 24), XMLNS(), + h.Title(link.Icon().Title), + Path(Fill("#"+link.Icon().Hex), D(link.Icon().Path)), + ), + h.Span(g.Text(link.Name)), + ) + }), + ), + }, + }) +} + +func ViewBox(minX, minY, width, height int) g.Node { + return g.Attr("viewBox", fmt.Sprintf("%d %d %d %d", minX, minY, width, height)) +} + +func XMLNS() g.Node { + return g.Attr("xmlns", "http://www.w3.org/2000/svg") +} + +func Path(children ...g.Node) g.Node { + return g.El("path", children...) +} + +func Fill(fill string) g.Node { + return g.Attr("fill", fill) +} + +func D(d string) g.Node { + return g.Attr("d", d) +} diff --git a/site.templ b/site.templ deleted file mode 100644 index f8f1d33..0000000 --- a/site.templ +++ /dev/null @@ -1,36 +0,0 @@ -package main - -templ head() { - - jolheiser - - - - - - -} - -func fill(hex string) string { - return "#" + hex -} - -templ body(links []Link) { - -
- avatar -

{ `@` }jolheiser

-
- - -} - -templ index(links []Link) { - @head() - @body(links) -} - diff --git a/site_templ.go b/site_templ.go deleted file mode 100644 index ead511f..0000000 --- a/site_templ.go +++ /dev/null @@ -1,203 +0,0 @@ -// Code generated by templ - DO NOT EDIT. - -// templ: version: v0.2.786 -package main - -//lint:file-ignore SA4006 This context is only used if a nested component is present. - -import "github.com/a-h/templ" -import templruntime "github.com/a-h/templ/runtime" - -func head() templ.Component { - return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { - templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context - if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { - return templ_7745c5c3_CtxErr - } - templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) - if !templ_7745c5c3_IsBuffer { - defer func() { - templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) - if templ_7745c5c3_Err == nil { - templ_7745c5c3_Err = templ_7745c5c3_BufErr - } - }() - } - ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var1 := templ.GetChildren(ctx) - if templ_7745c5c3_Var1 == nil { - templ_7745c5c3_Var1 = templ.NopComponent - } - ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("jolheiser") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - return templ_7745c5c3_Err - }) -} - -func fill(hex string) string { - return "#" + hex -} - -func body(links []Link) templ.Component { - return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { - templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context - if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { - return templ_7745c5c3_CtxErr - } - templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) - if !templ_7745c5c3_IsBuffer { - defer func() { - templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) - if templ_7745c5c3_Err == nil { - templ_7745c5c3_Err = templ_7745c5c3_BufErr - } - }() - } - ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var2 := templ.GetChildren(ctx) - if templ_7745c5c3_Var2 == nil { - templ_7745c5c3_Var2 = templ.NopComponent - } - ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
\"avatar\"

") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var3 string - templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(`@`) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `site.templ`, Line: 22, Col: 58} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("jolheiser

") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - return templ_7745c5c3_Err - }) -} - -func index(links []Link) templ.Component { - return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { - templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context - if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { - return templ_7745c5c3_CtxErr - } - templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) - if !templ_7745c5c3_IsBuffer { - defer func() { - templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) - if templ_7745c5c3_Err == nil { - templ_7745c5c3_Err = templ_7745c5c3_BufErr - } - }() - } - ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var10 := templ.GetChildren(ctx) - if templ_7745c5c3_Var10 == nil { - templ_7745c5c3_Var10 = templ.NopComponent - } - ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Err = head().Render(ctx, templ_7745c5c3_Buffer) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = body(links).Render(ctx, templ_7745c5c3_Buffer) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - return templ_7745c5c3_Err - }) -} - -var _ = templruntime.GeneratedTemplate diff --git a/tailwind.config.js b/tailwind.config.js index 0b0b81e..840ef08 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -1,6 +1,6 @@ /** @type {import('tailwindcss').Config} */ module.exports = { - content: ["./dist/*.html", "*.templ"], + content: ["./dist/*.html"], plugins: [require("@catppuccin/tailwindcss")], }