234 lines
9.6 KiB
Go
234 lines
9.6 KiB
Go
// 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 (
|
|
"strconv"
|
|
|
|
"git.grosinger.net/tgrosinger/saasitone/pkg/funcmap"
|
|
"git.grosinger.net/tgrosinger/saasitone/pkg/models"
|
|
"git.grosinger.net/tgrosinger/saasitone/pkg/page"
|
|
)
|
|
|
|
func Home(p page.Page, posts []models.Post) 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 p.HTMX.Request.Target != "posts" {
|
|
templ_7745c5c3_Err = topContent(p).Render(ctx, templ_7745c5c3_Buffer)
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
}
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div id=\"posts\">")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
for _, post := range posts {
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<article class=\"media\"><figure class=\"media-left\"><p class=\"image is-64x64\"><img src=\"")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
var templ_7745c5c3_Var2 string
|
|
templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(funcmap.File("gopher.png"))
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templ/pages/home.templ`, Line: 20, Col: 43}
|
|
}
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2))
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" alt=\"Gopher\"></p></figure><div class=\"media-content\"><div class=\"content\"><p><strong>")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
var templ_7745c5c3_Var3 string
|
|
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(post.Title)
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templ/pages/home.templ`, Line: 26, Col: 27}
|
|
}
|
|
_, 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("</strong><br>")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
var templ_7745c5c3_Var4 string
|
|
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(post.Body)
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templ/pages/home.templ`, Line: 28, Col: 18}
|
|
}
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</p></div></div></article>")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
}
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"field is-grouped is-grouped-centered\">")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
if !p.Pager.IsBeginning() {
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<p class=\"control\"><button class=\"button is-primary\" hx-swap=\"outerHTML\" hx-get=\"")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
var templ_7745c5c3_Var5 string
|
|
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs("/?page=" + strconv.Itoa(p.Pager.Page-1))
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templ/pages/home.templ`, Line: 37, Col: 108}
|
|
}
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" hx-target=\"#posts\">Previous page</button></p>")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
}
|
|
if !p.Pager.IsEnd() {
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<p class=\"control\"><button class=\"button is-primary\" hx-swap=\"outerHTML\" hx-get=\"")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
var templ_7745c5c3_Var6 string
|
|
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs("/?page=" + strconv.Itoa(p.Pager.Page+1))
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templ/pages/home.templ`, Line: 42, Col: 108}
|
|
}
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" hx-target=\"#posts\">Next page</button></p>")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
}
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div></div>")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
if p.HTMX.Request.Target != "posts" {
|
|
templ_7745c5c3_Err = fileMsg().Render(ctx, templ_7745c5c3_Buffer)
|
|
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 topContent(p page.Page) 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_Var7 := templ.GetChildren(ctx)
|
|
if templ_7745c5c3_Var7 == nil {
|
|
templ_7745c5c3_Var7 = templ.NopComponent
|
|
}
|
|
ctx = templ.ClearChildren(ctx)
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<section class=\"hero is-info welcome is-small\"><div class=\"hero-body\"><div class=\"container\"><h1 class=\"title\">")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
if p.IsAuth {
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Hello, ")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
var templ_7745c5c3_Var8 string
|
|
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(p.AuthUser.Name)
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templ/pages/home.templ`, Line: 58, Col: 30}
|
|
}
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
} else {
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Hello")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
}
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</h1><h2 class=\"subtitle\">")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
if p.IsAuth {
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Welcome back!")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
} else {
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Please login in to your account.")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
}
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</h2></div></div></section><section class=\"section\"><h1 class=\"title\">Recent posts</h1><h2 class=\"subtitle\">Below is an example of both paging and AJAX fetching using HTMX</h2></section>")
|
|
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 fileMsg() 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_Var9 := templ.GetChildren(ctx)
|
|
if templ_7745c5c3_Var9 == nil {
|
|
templ_7745c5c3_Var9 = templ.NopComponent
|
|
}
|
|
ctx = templ.ClearChildren(ctx)
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"block\"></div><article class=\"message is-small is-warning\" x-data=\"{show: true}\" x-show=\"show\"><div class=\"message-header\"><p>Serving files</p><button class=\"delete is-small\" aria-label=\"delete\" @click=\"show = false\"></button></div><div class=\"message-body\">In the example posts above, check how the file URL contains a cache-buster query parameter which changes only when the app is restarted. Static files also contain cache-control headers which are configured via middleware. You can also use AlpineJS to dismiss this message.</div></article>")
|
|
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
|
|
})
|
|
}
|