diff --git a/README.md b/README.md index 28756d6cbcef4913aec95a739b8622111fe547bd..ade5630f76373e291c6f0a1ff9af0cd5d8c5080b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # jolheiser.com My [personal website](https://jolheiser.com). -Uses [tailwind](https://tailwindcss.com/) (with [catppuccin btw](https://github.com/catppuccin/tailwindcss)) and [gomponents](https://gomponents.com) as a simple static page generator. +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. Links are sourced from [links.jsonnet](links.jsonnet). @@ -18,6 +18,7 @@ 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 c5bd9457651a4309c44c95a06261d7c629fc9976..c0ea666dfba512baf4d4debe07afd521fa07d9b0 100644 --- a/flake.lock +++ b/flake.lock @@ -18,6 +18,82 @@ "repo": "flake-utils", "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, @@ -38,7 +114,8 @@ "inputs": { "flake-utils": "flake-utils", "nixpkgs": "nixpkgs", "tailwind-ctp": "tailwind-ctp", - "tailwind-ctp-lsp": "tailwind-ctp-lsp" + "tailwind-ctp-lsp": "tailwind-ctp-lsp", + "templ": "templ" } }, "systems": { @@ -56,6 +133,21 @@ "repo": "default", "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": [ @@ -94,6 +186,51 @@ }, "original": { "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" } } }, diff --git a/flake.nix b/flake.nix index 880d2f01c255a0f0187aaf6fbc91eaca3e20cbc7..1d8cd452391098e16c768011c5d6ea5511956ec5 100644 --- a/flake.nix +++ b/flake.nix @@ -2,6 +2,10 @@ { 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"; @@ -12,28 +16,27 @@ inputs.nixpkgs.follows = "nixpkgs"; }; }; - outputs = - { - self, - flake-utils, - nixpkgs, - tailwind-ctp, - tailwind-ctp-lsp, - }@inputs: + outputs = { + self, + flake-utils, + nixpkgs, + templ, + 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; - in - { + templ = inputs.templ.packages.${system}.templ; + in { packages.default = pkgs.buildGoModule { pname = "jolheiser.com"; version = "site"; src = ./.; vendorHash = nixpkgs.lib.fileContents ./go.mod.sri; - nativeBuildInputs = [ tailwind-ctp ]; + nativeBuildInputs = [templ tailwind-ctp]; excludedPackages = "."; postBuild = '' go generate @@ -43,6 +46,7 @@ }; 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 a7f31231c72b0749d2d2566d06d140b30110a854..6fdac75d56847e20cd8856eba258905882139e5c 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 8989e01e68febd7e681bb5384a1356d7f48648e1..ac7c6efe8b49f46c1bdb25e6f2bcc2024896ea76 100644 --- a/go.mod.sri +++ b/go.mod.sri @@ -1 +1 @@ -sha256-e8dPVJnc7J9+9xGo+l1ccCzyF+iqOEGyRhRmdazmgCQ= \ No newline at end of file +sha256-LCjIObTQdTuKwkM+0DESmaC5gWlbX8rGQkL1hn6Iy8Q= \ No newline at end of file diff --git a/go.sum b/go.sum index 2e6b0d4c3f436e6fc469379d3473aaa4b64c711b..58ab33e95c25fa0c8226165c68643ffb18ce76a9 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,9 @@ 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= @@ -8,7 +12,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= 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 new file mode 100644 index 0000000000000000000000000000000000000000..84524f26d68cee0647056215875c84067e125ff1 --- /dev/null +++ b/justfile @@ -0,0 +1,6 @@ +build: + @git add . + @nix build + +generate: + @go generate diff --git a/main.go b/main.go index 7301df3a263c5d868e9e50a9436ac1d829666d19..05aa439e889bb65d9f4e3bb317b46346070d48ba 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "context" "encoding/json" "os" @@ -24,6 +25,7 @@ @tailwind components; @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() { @@ -50,7 +52,7 @@ panic(err) } defer html.Close() - err = index(links.Links).Render(html) + err = index(links.Links).Render(context.Background(), html) if err != nil { panic(err) } diff --git a/site.go b/site.go deleted file mode 100644 index 51af0c9e5002607a08062a999e77969eca046182..0000000000000000000000000000000000000000 --- a/site.go +++ /dev/null @@ -1,61 +0,0 @@ -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 new file mode 100644 index 0000000000000000000000000000000000000000..f8f1d33189ea89dfdce4c814469a9222f76979c4 --- /dev/null +++ b/site.templ @@ -0,0 +1,36 @@ +package main + +templ head() { +
+{ `@` }jolheiser
+") + 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