fix examples, add public folder for public files
This commit is contained in:
parent
575998c0e1
commit
16736e34eb
10 changed files with 149 additions and 43 deletions
21
LICENSE
21
LICENSE
|
|
@ -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.
|
||||
|
|
@ -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"),
|
||||
|
|
|
|||
0
htmgo-site/assets/public/todo-example.jpg
Normal file
0
htmgo-site/assets/public/todo-example.jpg
Normal file
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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, "")
|
||||
})
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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(`
|
||||
|
|
|
|||
|
|
@ -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"),
|
||||
|
|
|
|||
94
htmgo-site/pages/examples.go
Normal file
94
htmgo-site/pages/examples.go
Normal file
|
|
@ -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"),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
|
@ -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", ""),
|
||||
),
|
||||
),
|
||||
)),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)),
|
||||
),
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue