2024-09-20 16:45:23 +00:00
|
|
|
package partials
|
|
|
|
|
|
2024-09-21 03:59:07 +00:00
|
|
|
import (
|
2024-09-28 02:29:53 +00:00
|
|
|
"fmt"
|
2024-09-21 03:59:07 +00:00
|
|
|
"github.com/maddalax/htmgo/framework/h"
|
2024-09-27 02:15:04 +00:00
|
|
|
"htmgo-site/internal/httpjson"
|
|
|
|
|
"time"
|
2024-09-21 03:59:07 +00:00
|
|
|
)
|
2024-09-20 16:45:23 +00:00
|
|
|
|
|
|
|
|
type NavItem struct {
|
|
|
|
|
Name string
|
|
|
|
|
Url string
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-28 02:29:53 +00:00
|
|
|
var navItems = []NavItem{
|
|
|
|
|
{Name: "Docs", Url: "/docs"},
|
|
|
|
|
{Name: "Examples", Url: "/examples"},
|
2024-10-11 16:21:53 +00:00
|
|
|
{Name: "Convert HTML", Url: "/html-to-go"},
|
2024-09-28 02:29:53 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-13 13:24:23 +00:00
|
|
|
type NavBarProps struct {
|
|
|
|
|
Expanded bool
|
|
|
|
|
ShowPreRelease bool
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-20 20:15:12 +00:00
|
|
|
func ToggleNavbar(ctx *h.RequestContext) *h.Partial {
|
2024-09-21 16:52:56 +00:00
|
|
|
return h.SwapManyPartial(
|
|
|
|
|
ctx,
|
2024-09-27 02:15:04 +00:00
|
|
|
MobileNav(ctx, h.GetQueryParam(ctx, "expanded") == "true"),
|
2024-09-20 20:15:12 +00:00
|
|
|
)
|
|
|
|
|
}
|
2024-09-20 16:45:23 +00:00
|
|
|
|
2024-09-28 02:41:32 +00:00
|
|
|
var CachedStar = h.CachedT(time.Minute*15, func(t *h.RequestContext) *h.Element {
|
|
|
|
|
return Star(t)
|
|
|
|
|
})
|
|
|
|
|
|
2024-09-27 02:15:04 +00:00
|
|
|
func Star(ctx *h.RequestContext) *h.Element {
|
2024-09-26 22:00:30 +00:00
|
|
|
|
2024-09-27 02:15:04 +00:00
|
|
|
type Repo struct {
|
|
|
|
|
StarCount int `json:"stargazers_count"`
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-28 02:29:53 +00:00
|
|
|
fmt.Printf("making github star request\n")
|
|
|
|
|
count := 0
|
|
|
|
|
response, err := httpjson.Get[Repo]("https://api.github.com/repos/maddalax/htmgo")
|
|
|
|
|
|
|
|
|
|
if err == nil && response != nil {
|
|
|
|
|
count = response.StarCount
|
|
|
|
|
}
|
2024-09-27 02:15:04 +00:00
|
|
|
|
|
|
|
|
return h.A(
|
|
|
|
|
h.Href("https://github.com/maddalax/htmgo"),
|
|
|
|
|
h.Target("_blank"),
|
|
|
|
|
h.Class("inline-flex items-center rounded overflow-hidden shadow-sm"),
|
|
|
|
|
h.Div(
|
|
|
|
|
h.Class("flex items-center px-2 py-1 bg-gray-800 text-white text-sm font-semibold hover:bg-gray-700 transition"),
|
|
|
|
|
h.Svg(
|
2024-09-27 02:18:58 +00:00
|
|
|
h.Class("w-4 h-4 -mt-0.5 mr-0.5 stroke-current text-white"),
|
2024-09-27 02:15:04 +00:00
|
|
|
h.Attribute("xmlns", "http://www.w3.org/2000/svg"),
|
|
|
|
|
h.Attribute("viewBox", "0 0 24 24"),
|
2024-10-25 15:33:48 +00:00
|
|
|
h.Attribute("fill", "none"),
|
|
|
|
|
h.Attribute("stroke", "currentColor"),
|
|
|
|
|
h.Attribute("stroke-width", "2"),
|
2024-09-27 02:15:04 +00:00
|
|
|
h.Path(
|
|
|
|
|
h.D("M12 17.27l5.18 3.05-1.64-5.68 4.46-3.87-5.88-.5L12 3.5l-2.12 6.77-5.88.5 4.46 3.87-1.64 5.68L12 17.27z"),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
h.Text("Star"),
|
|
|
|
|
),
|
2024-10-25 15:33:48 +00:00
|
|
|
h.If(
|
|
|
|
|
count > 0,
|
|
|
|
|
h.Div(
|
|
|
|
|
h.Class("flex items-center px-3 py-1 bg-black text-white text-sm font-semibold"),
|
|
|
|
|
h.Pf("%d", count),
|
|
|
|
|
),
|
|
|
|
|
),
|
2024-09-24 18:23:38 +00:00
|
|
|
)
|
2024-09-20 20:15:12 +00:00
|
|
|
}
|
2024-09-20 16:45:23 +00:00
|
|
|
|
2024-10-13 13:24:23 +00:00
|
|
|
func NavBar(ctx *h.RequestContext, props NavBarProps) *h.Element {
|
2024-10-25 16:30:50 +00:00
|
|
|
banner := h.If(
|
|
|
|
|
true,
|
|
|
|
|
h.A(
|
|
|
|
|
h.Class("bg-blue-200 text-slate-700 text-center p-2 flex items-center justify-center"),
|
|
|
|
|
h.Href("https://github.com/maddalax/htmgo/releases/tag/framework%2Fv1.0.1"),
|
|
|
|
|
h.Attribute("target", "_blank"),
|
|
|
|
|
h.Text("htmgo v1.0.1 is released and it includes a new automatic formatter, view release notes"),
|
|
|
|
|
),
|
|
|
|
|
)
|
2024-09-20 20:15:12 +00:00
|
|
|
desktopNav := h.Nav(
|
2024-10-13 13:24:23 +00:00
|
|
|
h.Class("hidden sm:block bg-neutral-100 border border-b-slate-300 p-4 md:p-3 max-h-[100vh - 9rem] overflow-y-auto"),
|
2024-09-20 20:15:12 +00:00
|
|
|
h.Div(
|
2024-09-24 18:16:07 +00:00
|
|
|
h.Class("max-w-[95%] md:max-w-3xl px-4 mx-auto"),
|
2024-09-20 20:15:12 +00:00
|
|
|
h.Div(
|
|
|
|
|
h.Class("flex justify-between items-center"),
|
|
|
|
|
h.Div(
|
|
|
|
|
h.Class("flex items-center"),
|
|
|
|
|
h.A(
|
|
|
|
|
h.Class("text-2xl"),
|
|
|
|
|
h.Href("/"),
|
|
|
|
|
h.Text("htmgo"),
|
2024-10-25 15:33:48 +00:00
|
|
|
),
|
|
|
|
|
),
|
2024-10-15 15:26:30 +00:00
|
|
|
h.Div(
|
|
|
|
|
h.Id("search-container"),
|
|
|
|
|
),
|
2024-09-20 20:15:12 +00:00
|
|
|
h.Div(
|
|
|
|
|
h.Class("flex gap-4 items-center"),
|
|
|
|
|
h.List(navItems, func(item NavItem, index int) *h.Element {
|
|
|
|
|
return h.Div(
|
|
|
|
|
h.Class("flex items-center"),
|
|
|
|
|
h.A(
|
|
|
|
|
h.Class(""),
|
|
|
|
|
h.Href(item.Url),
|
|
|
|
|
h.Text(item.Name),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
}),
|
2024-09-28 02:29:53 +00:00
|
|
|
CachedStar(ctx),
|
2024-09-20 20:15:12 +00:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
|
2024-09-20 18:25:14 +00:00
|
|
|
return h.Div(
|
2024-09-20 20:15:12 +00:00
|
|
|
h.Id("navbar"),
|
2024-10-25 16:30:50 +00:00
|
|
|
banner,
|
2024-10-13 13:24:23 +00:00
|
|
|
MobileNav(ctx, props.Expanded),
|
2024-09-20 20:15:12 +00:00
|
|
|
desktopNav,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-27 02:15:04 +00:00
|
|
|
func MobileNav(ctx *h.RequestContext, expanded bool) *h.Element {
|
2024-09-20 20:15:12 +00:00
|
|
|
return h.Nav(
|
|
|
|
|
h.Id("mobile-nav"),
|
|
|
|
|
h.Class("block sm:hidden bg-neutral-100 border border-b-slate-300 p-4 md:p-3"),
|
|
|
|
|
h.Div(
|
|
|
|
|
h.Class("max-w-[95%] md:max-w-prose mx-auto"),
|
2024-09-20 16:45:23 +00:00
|
|
|
h.Div(
|
2024-09-20 20:15:12 +00:00
|
|
|
h.Class("flex justify-between items-center"),
|
2024-09-20 16:45:23 +00:00
|
|
|
h.Div(
|
2024-09-20 20:15:12 +00:00
|
|
|
h.Class("flex items-center"),
|
|
|
|
|
h.A(
|
2024-09-21 03:59:07 +00:00
|
|
|
h.Boost(),
|
2024-09-20 20:15:12 +00:00
|
|
|
h.Class("text-2xl"),
|
|
|
|
|
h.Href("/"),
|
|
|
|
|
h.Text("htmgo"),
|
2024-10-25 15:33:48 +00:00
|
|
|
),
|
|
|
|
|
),
|
2024-09-20 20:15:12 +00:00
|
|
|
h.Div(
|
2024-09-26 22:00:30 +00:00
|
|
|
h.Class("flex items-center gap-3"),
|
2024-10-25 15:33:48 +00:00
|
|
|
h.Div(
|
|
|
|
|
h.Class("mt-1"),
|
|
|
|
|
CachedStar(ctx),
|
|
|
|
|
),
|
2024-09-20 20:15:12 +00:00
|
|
|
h.Button(
|
2024-09-21 03:59:07 +00:00
|
|
|
h.Boost(),
|
|
|
|
|
h.GetPartialWithQs(
|
|
|
|
|
ToggleNavbar,
|
2024-10-25 15:33:48 +00:00
|
|
|
h.NewQs(
|
|
|
|
|
"expanded",
|
|
|
|
|
h.Ternary(expanded, "false", "true"),
|
|
|
|
|
"test",
|
|
|
|
|
"true",
|
|
|
|
|
),
|
2024-09-21 03:59:07 +00:00
|
|
|
"click",
|
|
|
|
|
),
|
|
|
|
|
h.AttributePairs(
|
2024-10-25 15:33:48 +00:00
|
|
|
"class",
|
|
|
|
|
"text-2xl",
|
|
|
|
|
"aria-expanded",
|
|
|
|
|
h.Ternary(expanded, "true", "false"),
|
2024-09-21 03:59:07 +00:00
|
|
|
),
|
2024-09-20 20:15:12 +00:00
|
|
|
h.Class("text-2xl"),
|
2024-09-29 02:02:57 +00:00
|
|
|
h.UnsafeRaw("☰"),
|
2024-09-20 18:25:14 +00:00
|
|
|
),
|
2024-09-20 16:45:23 +00:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
2024-10-25 15:33:48 +00:00
|
|
|
h.If(
|
|
|
|
|
expanded,
|
|
|
|
|
h.Div(
|
|
|
|
|
h.Class("mt-2 ml-2 flex flex-col gap-2"),
|
|
|
|
|
h.List(navItems, func(item NavItem, index int) *h.Element {
|
|
|
|
|
return h.Div(
|
|
|
|
|
h.Class("flex items-center"),
|
|
|
|
|
h.A(
|
|
|
|
|
h.Boost(),
|
|
|
|
|
h.Class(""),
|
|
|
|
|
h.Href(item.Url),
|
|
|
|
|
h.Text(item.Name),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
}),
|
|
|
|
|
),
|
|
|
|
|
),
|
2024-09-20 16:45:23 +00:00
|
|
|
)
|
|
|
|
|
}
|