From 16736e34eb9cd8ffd77ae2e59414cbc03f6d2223 Mon Sep 17 00:00:00 2001 From: maddalax Date: Tue, 24 Sep 2024 22:41:03 -0500 Subject: [PATCH] fix examples, add public folder for public files --- LICENSE | 21 ----- cli/htmgo/tasks/copyassets/bundle.go | 7 ++ htmgo-site/assets/public/todo-example.jpg | 0 htmgo-site/go.mod | 2 +- htmgo-site/main.go | 5 -- htmgo-site/pages/base/root.go | 4 + htmgo-site/pages/docs.go | 4 +- htmgo-site/pages/examples.go | 94 +++++++++++++++++++++++ htmgo-site/pages/index.go | 37 ++++++++- htmgo-site/pages/markdown.go | 18 ++--- 10 files changed, 149 insertions(+), 43 deletions(-) delete mode 100644 LICENSE create mode 100644 htmgo-site/assets/public/todo-example.jpg create mode 100644 htmgo-site/pages/examples.go diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 99d455c..0000000 --- a/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2024 maddalax - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/cli/htmgo/tasks/copyassets/bundle.go b/cli/htmgo/tasks/copyassets/bundle.go index bf8cda7..99430b8 100644 --- a/cli/htmgo/tasks/copyassets/bundle.go +++ b/cli/htmgo/tasks/copyassets/bundle.go @@ -83,6 +83,13 @@ func CopyAssets() { log.Fatalf("Error: %v", err) } + if dirutil.HasFileFromRoot("assets/public") { + err = dirutil.CopyDir(filepath.Join(process.GetWorkingDir(), "assets/public"), filepath.Join(process.GetWorkingDir(), "assets/dist"), + func(path string, exists bool) bool { + return true + }) + } + if !dirutil.HasFileFromRoot("tailwind.config.js") { err = dirutil.CopyFile( filepath.Join(assetCssDir, "tailwind.config.js"), diff --git a/htmgo-site/assets/public/todo-example.jpg b/htmgo-site/assets/public/todo-example.jpg new file mode 100644 index 0000000..e69de29 diff --git a/htmgo-site/go.mod b/htmgo-site/go.mod index a58fa75..06ecf39 100644 --- a/htmgo-site/go.mod +++ b/htmgo-site/go.mod @@ -14,7 +14,7 @@ require ( github.com/dlclark/regexp2 v1.7.0 // indirect github.com/google/uuid v1.6.0 // indirect github.com/labstack/gommon v0.4.2 // indirect - github.com/maddalax/htmgo/framework v0.0.0-20240924203546-811f64f4619f // indirect + github.com/maddalax/htmgo/framework v0.0.0-20240924205924-e50bbff365a6 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect diff --git a/htmgo-site/main.go b/htmgo-site/main.go index 06ed2f9..5ddc257 100644 --- a/htmgo-site/main.go +++ b/htmgo-site/main.go @@ -8,7 +8,6 @@ import ( _ "github.com/mattn/go-sqlite3" "htmgo-site/__htmgo" "htmgo-site/internal/markdown" - "htmgo-site/pages" "io/fs" ) @@ -43,10 +42,6 @@ func main() { }) __htmgo.Register(e) - - pages.RegisterMarkdown(e, "md", MarkdownAssets, func(ctx echo.Context, path string) error { - return pages.MarkdownHandler(ctx.(*h.RequestContext), path, "") - }) }, }) } diff --git a/htmgo-site/pages/base/root.go b/htmgo-site/pages/base/root.go index a51c4e5..26fce46 100644 --- a/htmgo-site/pages/base/root.go +++ b/htmgo-site/pages/base/root.go @@ -13,6 +13,10 @@ func RootPage(children ...h.Ren) *h.Element { h.HxExtension(h.BaseExtensions()), h.Head( h.Meta("viewport", "width=device-width, initial-scale=1"), + h.Meta("og:title", "htmgo"), + h.Meta("og:url", "https://htmgo.dev"), + h.Link("canonical", "https://htmgo.dev"), + h.Meta("og:description", "build simple and scalable systems with go + htmx"), h.LinkWithVersion("/public/main.css", "stylesheet", Version), h.ScriptWithVersion("/public/htmgo.js", Version), h.Raw(` diff --git a/htmgo-site/pages/docs.go b/htmgo-site/pages/docs.go index e4f81c4..10f2a56 100644 --- a/htmgo-site/pages/docs.go +++ b/htmgo-site/pages/docs.go @@ -17,11 +17,11 @@ func DocsPage(ctx *h.RequestContext) *h.Page { h.Class("flex flex-col md:flex-row gap-4 justify-center mb-12"), partials.DocSidebar(pages), h.Div( - h.Class("flex flex-col justify-center items-center mt-6"), + h.Class("flex flex-col justify-center items-center md:mt-6"), h.List(pages, func(page *dirwalk.Page, index int) *h.Element { anchor := partials.CreateAnchor(page.Parts) return h.Div( - h.Class("border-b border-b-slate-300 w-full pb-8 mb-8"), + h.Class("border-b border-b-slate-300 w-full pb-8 mb-8 p-4 md:p-0"), MarkdownContent(ctx, page.FilePath, anchor), h.Div( h.Class("ml-4 pl-1 mt-2 bg-rose-200"), diff --git a/htmgo-site/pages/examples.go b/htmgo-site/pages/examples.go new file mode 100644 index 0000000..690d5cb --- /dev/null +++ b/htmgo-site/pages/examples.go @@ -0,0 +1,94 @@ +package pages + +import ( + "github.com/maddalax/htmgo/framework/h" + "htmgo-site/pages/base" +) + +type Example struct { + Title string + Github string + Demo string +} + +var examples = []Example{ + { + Title: "Todo List MVC", + Github: "https://github.com/maddalax/htmgo/tree/master/examples/todo-list", + Demo: "https://todo-example.htmgo.dev", + }, +} + +func ExamplesPage(ctx *h.RequestContext) *h.Page { + return h.NewPage( + base.RootPage(h.Div( + h.Class("flex items-center justify-center"), + h.Div( + h.Class("w-full px-4 flex flex-col prose max-w-[95vw] md:max-w-3xl mt-6"), + h.Div( + h.Class("flex flex-col mb-6 md:mb-0 md:flex-row justify-between items-center"), + h.Div( + h.H1( + h.Class("text-center md:text-left"), + h.Text("htmgo examples"), + ), + h.H3( + h.Class("-mt-4"), + h.TextF("example projects built with htmgo"), + ), + ), + ), + h.Div( + h.Class("border-b border-b-slate-200 h-1"), + h.Div( + h.Class("mt-4"), + ExampleCards(), + ), + ), + )), + ), + ) +} + +func ExampleCards() *h.Element { + return h.Div( + h.Class("prose-h2:my-1 prose-img:my-1 flex flex-wrap gap-4 justify-start"), // Left-aligns and allows multiple cards in a row + h.List(examples, func(example Example, index int) *h.Element { + return h.Div( + h.Class("border border-gray-200 shadow-sm rounded-md px-4 pb-4 w-full md:w-1/2"), // Reduces padding + h.Div( + h.Class("flex flex-col gap-1 mt-4"), + h.H2( + h.Class("text-lg text-center mb-1"), // Reduced margin at the bottom of the title + h.Text(example.Title), + ), + h.Div( + h.A( + h.Href(example.Demo), + h.Class("not-prose"), + h.Img( + h.Src("public/todo-example.jpg"), + h.Class("md:w-full rounded-md mx-auto"), + ), + ), // Ensures image is centered within the card + ), + h.Div( + h.Div( + h.Class("flex gap-2 justify-center mt-2"), // Slight margin-top for spacing from the image + h.A( + h.Href(example.Github), + h.Class("not-prose p-2 bg-slate-900 text-white rounded-md"), // Reduced padding for the buttons + h.Text("Github"), + ), + h.A( + h.Href(example.Demo), + h.Class("not-prose p-2 bg-slate-900 text-white rounded-md"), // Reduced padding for the buttons + h.Text("Demo"), + ), + ), + ), + ), + ) + }), + ) +} diff --git a/htmgo-site/pages/index.go b/htmgo-site/pages/index.go index 9b7a1af..7f010d6 100644 --- a/htmgo-site/pages/index.go +++ b/htmgo-site/pages/index.go @@ -2,8 +2,43 @@ package pages import ( "github.com/maddalax/htmgo/framework/h" + "htmgo-site/pages/base" ) func IndexPage(ctx *h.RequestContext) *h.Page { - return h.NewPage(MarkdownPage(ctx, "md/index.md", "")) + return h.NewPage( + base.RootPage(h.Div( + h.Class("flex items-center justify-center"), + h.Div( + h.Class("w-full px-4 flex flex-col prose max-w-[95vw] md:max-w-3xl mt-6"), + h.Div( + h.Class("flex flex-col mb-6 md:mb-0 md:flex-row justify-between items-center"), + h.Div( + h.H1( + h.Class("text-center md:text-left"), + h.Text("htmgo"), + ), + h.H3( + h.Class("-mt-4"), + h.TextF("build simple and scalable systems with go + htmx"), + ), + ), + h.Div( + h.A( + h.Href("/docs"), + h.Class("not-prose p-3 bg-slate-900 text-white rounded-md"), + h.Text("Get Started"), + ), + ), + ), + h.Div( + h.Class("border-b border-b-slate-200 h-1"), + h.Div( + h.Class("mt-4"), + MarkdownPage(ctx, "md/index.md", ""), + ), + ), + )), + ), + ) } diff --git a/htmgo-site/pages/markdown.go b/htmgo-site/pages/markdown.go index b769d49..0eb9a36 100644 --- a/htmgo-site/pages/markdown.go +++ b/htmgo-site/pages/markdown.go @@ -5,21 +5,13 @@ import ( "github.com/maddalax/htmgo/framework/h" "github.com/maddalax/htmgo/framework/service" "htmgo-site/internal/markdown" - "htmgo-site/pages/base" ) -func MarkdownHandler(ctx *h.RequestContext, path string, id string) error { - return h.HtmlView(ctx, h.NewPage(MarkdownPage(ctx, path, id))) -} - func MarkdownPage(ctx *h.RequestContext, path string, id string) *h.Element { - return base.RootPage( + return h.Div( + MarkdownContent(ctx, path, id), h.Div( - h.Class("w-full p-4 flex flex-col justify-center items-center"), - MarkdownContent(ctx, path, id), - h.Div( - h.Class("min-h-12"), - ), + h.Class("min-h-12"), ), ) } @@ -29,8 +21,8 @@ func MarkdownContent(ctx *h.RequestContext, path string, id string) *h.Element { renderer := service.Get[markdown.Renderer](ctx.ServiceLocator()) return h.Div( h.If(id != "", h.Id(id)), - h.Article( - h.Class("prose max-w-[95vw] md:max-w-3xl px-4 prose-code:text-black prose-p:my-1"), + h.Div( + h.Class("w-full flex flex-col prose max-w-[95vw] md:max-w-3xl prose-code:text-black prose-p:my-1"), h.Raw(renderer.RenderFile(path, embeddedMd)), ), )