diff --git a/pkg/handlers/pages.go b/pkg/handlers/pages.go index bfade70..5d030bc 100644 --- a/pkg/handlers/pages.go +++ b/pkg/handlers/pages.go @@ -1,8 +1,6 @@ package handlers import ( - "html/template" - "github.com/a-h/templ" "github.com/labstack/echo/v4" @@ -23,17 +21,6 @@ type ( *services.TemplateRenderer *services.DBClient } - - aboutData struct { - ShowCacheWarning bool - FrontendTabs []aboutTab - BackendTabs []aboutTab - } - - aboutTab struct { - Title string - Body template.HTML - } ) func init() { @@ -71,7 +58,6 @@ func (h *Pages) Home(ctx echo.Context) error { func (h *Pages) About(ctx echo.Context) error { p := page.New(ctx) - p.Layout = templates.LayoutMain p.Name = templates.PageAbout p.Title = "About" @@ -81,33 +67,40 @@ func (h *Pages) About(ctx echo.Context) error { // A simple example of how the Data field can contain anything you want to send to the templates // even though you wouldn't normally send markup like this - p.Data = aboutData{ + data := pages.AboutData{ ShowCacheWarning: true, - FrontendTabs: []aboutTab{ + FrontendTabs: []pages.AboutTab{ { Title: "HTMX", - Body: template.HTML(`Completes HTML as a hypertext by providing attributes to AJAXify anything and much more. Visit htmx.org to learn more.`), + Body: `Completes HTML as a hypertext by providing attributes to AJAXify anything and much more. Visit htmx.org to learn more.`, }, { Title: "Alpine.js", - Body: template.HTML(`Drop-in, Vue-like functionality written directly in your markup. Visit alpinejs.dev to learn more.`), + Body: `Drop-in, Vue-like functionality written directly in your markup. Visit alpinejs.dev to learn more.`, }, { Title: "Bulma", - Body: template.HTML(`Ready-to-use frontend components that you can easily combine to build responsive web interfaces with no JavaScript requirements. Visit bulma.io to learn more.`), + Body: `Ready-to-use frontend components that you can easily combine to build responsive web interfaces with no JavaScript requirements. Visit bulma.io to learn more.`, }, }, - BackendTabs: []aboutTab{ + BackendTabs: []pages.AboutTab{ { Title: "Echo", - Body: template.HTML(`High performance, extensible, minimalist Go web framework. Visit echo.labstack.com to learn more.`), + Body: `High performance, extensible, minimalist Go web framework. Visit echo.labstack.com to learn more.`, }, { Title: "Ent", - Body: template.HTML(`Simple, yet powerful ORM for modeling and querying data. Visit entgo.io to learn more.`), + Body: `Simple, yet powerful ORM for modeling and querying data. Visit entgo.io to learn more.`, }, }, } - return h.RenderPage(ctx, p) + component := pages.About(p, data) + + // TODO: This can be reused + p.LayoutComponent = func(content templ.Component) templ.Component { + return layouts.Main(p, content) + } + + return h.RenderPageTempl(ctx, p, component) } diff --git a/templ/pages/about.templ b/templ/pages/about.templ new file mode 100644 index 0000000..6efb211 --- /dev/null +++ b/templ/pages/about.templ @@ -0,0 +1,63 @@ +package pages + +import ( + "strconv" + "fmt" + + "git.grosinger.net/tgrosinger/saasitone/pkg/page" +) + +type AboutData struct { + ShowCacheWarning bool + FrontendTabs []AboutTab + BackendTabs []AboutTab +} + +type AboutTab struct { + Title string + Body string +} + +templ About(p page.Page, data AboutData) { + if len(data.FrontendTabs) > 0 { +

Frontend

+

The following incredible projects make developing advanced, modern frontends possible and simple without having to write a single line of JS or CSS. You can go extremely far without leaving the comfort of Go with server-side rendered HTML.

+ @tabs(data.FrontendTabs) +
+ } + if len(data.BackendTabs) > 0 { +

Backend

+

The following incredible projects provide the foundation of the Go backend. See the repository for a complete list of included projects.

+ @tabs(data.BackendTabs) +
+ } + if (data.ShowCacheWarning) { +
+
+

Warning

+
+
+ This route has caching enabled so hot-reloading in the local environment will not work. +
+
+ } +} + +templ tabs(t []AboutTab) { +
+
+
+ } +
+} diff --git a/templ/pages/about_templ.go b/templ/pages/about_templ.go new file mode 100644 index 0000000..5c111c3 --- /dev/null +++ b/templ/pages/about_templ.go @@ -0,0 +1,187 @@ +// Code generated by templ - DO NOT EDIT. + +// templ: version: v0.2.707 +package pages + +//lint:file-ignore SA4006 This context is only used if a nested component is present. + +import "github.com/a-h/templ" +import "context" +import "io" +import "bytes" + +import ( + "fmt" + "strconv" + + "git.grosinger.net/tgrosinger/saasitone/pkg/page" +) + +type AboutData struct { + ShowCacheWarning bool + FrontendTabs []AboutTab + BackendTabs []AboutTab +} + +type AboutTab struct { + Title string + Body string +} + +func About(p page.Page, data AboutData) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var1 := templ.GetChildren(ctx) + if templ_7745c5c3_Var1 == nil { + templ_7745c5c3_Var1 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + if len(data.FrontendTabs) > 0 { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

Frontend

The following incredible projects make developing advanced, modern frontends possible and simple without having to write a single line of JS or CSS. You can go extremely far without leaving the comfort of Go with server-side rendered HTML.

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = tabs(data.FrontendTabs).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + if len(data.BackendTabs) > 0 { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

Backend

The following incredible projects provide the foundation of the Go backend. See the repository for a complete list of included projects.

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = tabs(data.BackendTabs).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + if data.ShowCacheWarning { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

Warning

This route has caching enabled so hot-reloading in the local environment will not work.
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func tabs(t []AboutTab) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + 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("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + for i, tab := range t { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templ.Raw(tab.Body).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} diff --git a/templates/pages/about.gohtml b/templates/pages/about.gohtml deleted file mode 100644 index 2905bb0..0000000 --- a/templates/pages/about.gohtml +++ /dev/null @@ -1,41 +0,0 @@ -{{define "content"}} - {{- if .Data.FrontendTabs}} -

Frontend

-

The following incredible projects make developing advanced, modern frontends possible and simple without having to write a single line of JS or CSS. You can go extremely far without leaving the comfort of Go with server-side rendered HTML.

- {{template "tabs" .Data.FrontendTabs}} -
- {{- end}} - - {{- if .Data.BackendTabs}} -

Backend

-

The following incredible projects provide the foundation of the Go backend. See the repository for a complete list of included projects.

- {{template "tabs" .Data.BackendTabs}} -
- {{end}} - - {{- if .Data.ShowCacheWarning}} -
-
-

Warning

-
-
- This route has caching enabled so hot-reloading in the local environment will not work. -
-
- {{- end}} -{{end}} - -{{define "tabs"}} -
-
- -
- {{- range $index, $tab := .}} -

→ {{.Body}}

- {{- end}} -
-{{end}} \ No newline at end of file