From 8b0b07694ec8319e5c4611a9f4ef82ea3079941a Mon Sep 17 00:00:00 2001 From: Graham Barber Date: Tue, 20 Aug 2024 12:22:34 -0700 Subject: [PATCH] add post page styles, extract sidebar layout --- handlers/routes.go | 4 +- html/components/head.templ | 21 ++++ html/components/head_templ.go | 101 +++++++++++++++++ html/components/posts/note.templ | 10 +- html/components/posts/note_templ.go | 10 +- html/components/posts/photo.templ | 28 +++-- html/components/posts/photo_templ.go | 18 ++- html/components/posts/post.templ | 116 ++++++++++--------- html/components/posts/post_templ.go | 83 +++++++++++--- html/components/posts/unsupported.templ | 59 +++++----- html/components/posts/unsupported_templ.go | 7 +- html/components/sidebar.templ | 12 ++ html/components/sidebar_templ.go | 35 ++++++ html/layouts/default.templ | 43 +++---- html/layouts/default_templ.go | 75 ++----------- html/layouts/sidebar.templ | 29 +++++ html/layouts/sidebar_templ.go | 70 ++++++++++++ html/pages/auth.templ | 123 ++++++++++----------- html/pages/auth_templ.go | 76 ++++++------- html/pages/home.templ | 46 +++----- html/pages/home_templ.go | 14 +-- html/pages/post.templ | 78 ++++--------- html/pages/post_templ.go | 98 ++-------------- models/post.go | 4 + 24 files changed, 641 insertions(+), 519 deletions(-) create mode 100644 html/components/head.templ create mode 100644 html/components/head_templ.go create mode 100644 html/components/sidebar.templ create mode 100644 html/components/sidebar_templ.go create mode 100644 html/layouts/sidebar.templ create mode 100644 html/layouts/sidebar_templ.go diff --git a/handlers/routes.go b/handlers/routes.go index ca0fe3e..94fa04c 100644 --- a/handlers/routes.go +++ b/handlers/routes.go @@ -18,7 +18,7 @@ func ServeHomePage(w http.ResponseWriter, r *http.Request) { panic(result.Error) } - layouts.RenderDefault("", pages.Home(posts)).ServeHTTP(w, r) + layouts.RenderWithSidebar("", pages.Home(posts)).ServeHTTP(w, r) } func ServePostPage(w http.ResponseWriter, r *http.Request) { @@ -32,5 +32,5 @@ func ServePostPage(w http.ResponseWriter, r *http.Request) { return } - layouts.RenderDefault(string(post.MicroformatType), pages.Post(post)).ServeHTTP(w, r) + layouts.RenderWithSidebar(string(post.MicroformatType), pages.Post(post)).ServeHTTP(w, r) } diff --git a/html/components/head.templ b/html/components/head.templ new file mode 100644 index 0000000..862c3a0 --- /dev/null +++ b/html/components/head.templ @@ -0,0 +1,21 @@ +package components + +import "github.com/puregarlic/space/storage" + +templ Head(title string) { + + if len(title) > 0 { + { title } | puregarlic dot space + } else { + puregarlic dot space + } + + + + + for _, rel := range storage.GetRels() { + + } + + +} diff --git a/html/components/head_templ.go b/html/components/head_templ.go new file mode 100644 index 0000000..4975611 --- /dev/null +++ b/html/components/head_templ.go @@ -0,0 +1,101 @@ +// Code generated by templ - DO NOT EDIT. + +// templ: version: v0.2.747 +package components + +//lint:file-ignore SA4006 This context is only used if a nested component is present. + +import "github.com/a-h/templ" +import templruntime "github.com/a-h/templ/runtime" + +import "github.com/puregarlic/space/storage" + +func Head(title string) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var1 := templ.GetChildren(ctx) + if templ_7745c5c3_Var1 == nil { + templ_7745c5c3_Var1 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 1) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if len(title) > 0 { + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 2) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var2 string + templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(title) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `html/components/head.templ`, Line: 8, Col: 17} + } + _, 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.WriteWatchModeString(templ_7745c5c3_Buffer, 3) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } else { + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 4) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 5) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + for _, rel := range storage.GetRels() { + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 6) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var3 string + templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(rel.Name) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `html/components/head.templ`, Line: 17, Col: 23} + } + _, 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.WriteWatchModeString(templ_7745c5c3_Buffer, 7) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var4 string + templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(rel.HREF) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `html/components/head.templ`, Line: 17, Col: 41} + } + _, 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.WriteWatchModeString(templ_7745c5c3_Buffer, 8) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 9) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return templ_7745c5c3_Err + }) +} diff --git a/html/components/posts/note.templ b/html/components/posts/note.templ index ebb5557..064df3c 100644 --- a/html/components/posts/note.templ +++ b/html/components/posts/note.templ @@ -1,11 +1,9 @@ package posts -import ( - "github.com/puregarlic/space/models" -) +import "github.com/puregarlic/space/models" templ Note(post *models.Post) { -
- {GetPostJSONProperty(post, "content")[0]} -
+
+ { GetPostJSONProperty(post, "content")[0] } +
} diff --git a/html/components/posts/note_templ.go b/html/components/posts/note_templ.go index 20cab48..43fd0e1 100644 --- a/html/components/posts/note_templ.go +++ b/html/components/posts/note_templ.go @@ -8,9 +8,7 @@ package posts import "github.com/a-h/templ" import templruntime "github.com/a-h/templ/runtime" -import ( - "github.com/puregarlic/space/models" -) +import "github.com/puregarlic/space/models" func Note(post *models.Post) templ.Component { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { @@ -30,20 +28,20 @@ func Note(post *models.Post) templ.Component { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 1) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var2 string templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(GetPostJSONProperty(post, "content")[0]) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `html/components/posts/note.templ`, Line: 9, Col: 43} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `html/components/posts/note.templ`, Line: 7, 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("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 2) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/html/components/posts/photo.templ b/html/components/posts/photo.templ index b8ac654..fa2cc0c 100644 --- a/html/components/posts/photo.templ +++ b/html/components/posts/photo.templ @@ -1,20 +1,18 @@ package posts -import ( - "github.com/puregarlic/space/models" -) +import "github.com/puregarlic/space/models" templ Photo(post *models.Post) { -
- for index, photo := range GetPostJSONProperty(post, "photo") { -
- -
- {GetPostJSONProperty(post, "content")[index]} -
-
- } -
+
+ for index, photo := range GetPostJSONProperty(post, "photo") { +
+ +
+ { GetPostJSONProperty(post, "content")[index] } +
+
+ } +
} diff --git a/html/components/posts/photo_templ.go b/html/components/posts/photo_templ.go index 411d49b..a568013 100644 --- a/html/components/posts/photo_templ.go +++ b/html/components/posts/photo_templ.go @@ -8,9 +8,7 @@ package posts import "github.com/a-h/templ" import templruntime "github.com/a-h/templ/runtime" -import ( - "github.com/puregarlic/space/models" -) +import "github.com/puregarlic/space/models" func Photo(post *models.Post) templ.Component { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { @@ -30,43 +28,43 @@ func Photo(post *models.Post) templ.Component { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 1) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } for index, photo := range GetPostJSONProperty(post, "photo") { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 3) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var3 string templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(GetPostJSONProperty(post, "content")[index]) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `html/components/posts/photo.templ`, Line: 15, Col: 52} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `html/components/posts/photo.templ`, Line: 13, Col: 50} } _, 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("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 4) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 5) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/html/components/posts/post.templ b/html/components/posts/post.templ index ad44de7..96a3fba 100644 --- a/html/components/posts/post.templ +++ b/html/components/posts/post.templ @@ -1,76 +1,92 @@ package posts import ( - "fmt" "encoding/json" + "fmt" - "github.com/puregarlic/space/models" - - "github.com/samber/lo" + "github.com/puregarlic/space/models" + "github.com/samber/lo" "go.hacdias.com/indielib/microformats" ) var ImplementedPostTypes = []microformats.Type{ - microformats.TypeNote, - microformats.TypePhoto, + microformats.TypeNote, + microformats.TypePhoto, } func GetPostJSONProperty(post *models.Post, name string) []string { - var tmp map[string]any - if err := json.Unmarshal(post.Properties, &tmp); err != nil { - panic(err) - } + var tmp map[string]any + if err := json.Unmarshal(post.Properties, &tmp); err != nil { + panic(err) + } - prop, ok := tmp[name] - if !ok { - return []string{""} - } + prop, ok := tmp[name] + if !ok { + return []string{""} + } - var out []string - for _, val := range prop.([]any) { - out = append(out, val.(string)) - } + var out []string + for _, val := range prop.([]any) { + out = append(out, val.(string)) + } - return out + return out } func formatPostTypeName(mfType microformats.Type) string { - has := lo.ContainsBy(ImplementedPostTypes, func(postType microformats.Type) bool { - return postType == mfType - }) + has := lo.ContainsBy(ImplementedPostTypes, func(postType microformats.Type) bool { + return postType == mfType + }) - if has { - return string(mfType) - } else { - return fmt.Sprintf("oops! (%s)", string(mfType)) - } + if has { + return string(mfType) + } else { + return fmt.Sprintf("%s (oops!)", string(mfType)) + } } templ PostFeedHeader(post *models.Post) { -
-

{ formatPostTypeName(post.MicroformatType) }

- - { post.CreatedAt.Format("01/02/2006 at 3:04 PM") } - - - - - -
+
+

{ post.Timestamp() }

+

+ { formatPostTypeName(post.MicroformatType) } + • + + open + + + + + +

+
+} + +templ PostDetails(post *models.Post) { +
+
+
Posted At
+
{ post.Timestamp() }
+
+
+
Post Type
+
{ string(post.MicroformatType) }
+
+
} templ PostContent(post *models.Post) { - switch post.MicroformatType { - case microformats.TypePhoto: - @Photo(post) - case microformats.TypeNote: - @Note(post) - default: - @Unsupported(post) - } + switch post.MicroformatType { + case microformats.TypePhoto: + @Photo(post) + case microformats.TypeNote: + @Note(post) + default: + @Unsupported(post) + } } diff --git a/html/components/posts/post_templ.go b/html/components/posts/post_templ.go index 8f32331..26bc643 100644 --- a/html/components/posts/post_templ.go +++ b/html/components/posts/post_templ.go @@ -13,7 +13,6 @@ import ( "fmt" "github.com/puregarlic/space/models" - "github.com/samber/lo" "go.hacdias.com/indielib/microformats" ) @@ -50,7 +49,7 @@ func formatPostTypeName(mfType microformats.Type) string { if has { return string(mfType) } else { - return fmt.Sprintf("oops! (%s)", string(mfType)) + return fmt.Sprintf("%s (oops!)", string(mfType)) } } @@ -72,42 +71,42 @@ func PostFeedHeader(post *models.Post) templ.Component { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 1) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var2 string - templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(formatPostTypeName(post.MicroformatType)) + templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(post.Timestamp()) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `html/components/posts/post.templ`, Line: 51, Col: 49} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `html/components/posts/post.templ`, Line: 50, Col: 23} } _, 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("

") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var4 string - templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(post.CreatedAt.Format("01/02/2006 at 3:04 PM")) + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 3) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `html/components/posts/post.templ`, Line: 58, Col: 53} + return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) + var templ_7745c5c3_Var4 templ.SafeURL = templ.URL("/posts/" + post.ID.String()) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(string(templ_7745c5c3_Var4))) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 4) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -115,7 +114,7 @@ func PostFeedHeader(post *models.Post) templ.Component { }) } -func PostContent(post *models.Post) templ.Component { +func PostDetails(post *models.Post) templ.Component { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) @@ -133,6 +132,58 @@ func PostContent(post *models.Post) templ.Component { templ_7745c5c3_Var5 = templ.NopComponent } ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 5) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var6 string + templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(post.Timestamp()) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `html/components/posts/post.templ`, Line: 74, Col: 45} + } + _, 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.WriteWatchModeString(templ_7745c5c3_Buffer, 6) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var7 string + templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(string(post.MicroformatType)) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `html/components/posts/post.templ`, Line: 78, Col: 57} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 7) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return templ_7745c5c3_Err + }) +} + +func PostContent(post *models.Post) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var8 := templ.GetChildren(ctx) + if templ_7745c5c3_Var8 == nil { + templ_7745c5c3_Var8 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) switch post.MicroformatType { case microformats.TypePhoto: templ_7745c5c3_Err = Photo(post).Render(ctx, templ_7745c5c3_Buffer) diff --git a/html/components/posts/unsupported.templ b/html/components/posts/unsupported.templ index 1a9d693..cffc0f1 100644 --- a/html/components/posts/unsupported.templ +++ b/html/components/posts/unsupported.templ @@ -1,14 +1,13 @@ package posts import ( - "bytes" - "encoding/json" + "bytes" + "encoding/json" - "github.com/puregarlic/space/models" - - "github.com/alecthomas/chroma/v2/formatters/html" - "github.com/alecthomas/chroma/v2/styles" - "github.com/alecthomas/chroma/v2/lexers" + "github.com/alecthomas/chroma/v2/formatters/html" + "github.com/alecthomas/chroma/v2/lexers" + "github.com/alecthomas/chroma/v2/styles" + "github.com/puregarlic/space/models" ) var style = styles.Get("rose-pine") @@ -18,39 +17,39 @@ var formatter = html.New(html.TabWidth(2), html.WithClasses(true)) var dedupeSyntaxStyles = templ.NewOnceHandle() func renderPostAsJSON(post *models.Post) string { - contents, err := json.MarshalIndent(post.Properties, "", " ") - if err != nil { - panic(err) - } + contents, err := json.MarshalIndent(post.Properties, "", " ") + if err != nil { + panic(err) + } - iterator, err := lexer.Tokenise(nil, string(contents)) + iterator, err := lexer.Tokenise(nil, string(contents)) - var buf bytes.Buffer - formatter.Format(&buf, style, iterator) + var buf bytes.Buffer + formatter.Format(&buf, style, iterator) - return buf.String() + return buf.String() } func generateSyntaxClassNames() string { - var buf bytes.Buffer - if err := formatter.WriteCSS(&buf, style); err != nil { - panic(err) - } - - return "" + var buf bytes.Buffer + if err := formatter.WriteCSS(&buf, style); err != nil { + panic(err) + } + + return "" } templ syntaxStyleTag() { - @templ.Raw(generateSyntaxClassNames()) + @templ.Raw(generateSyntaxClassNames()) } templ Unsupported(post *models.Post) { -
- @dedupeSyntaxStyles.Once() { - @syntaxStyleTag() - } - @templ.Raw(renderPostAsJSON(post)) -
+
+ @dedupeSyntaxStyles.Once() { + @syntaxStyleTag() + } + @templ.Raw(renderPostAsJSON(post)) +
} diff --git a/html/components/posts/unsupported_templ.go b/html/components/posts/unsupported_templ.go index 4013397..412f76a 100644 --- a/html/components/posts/unsupported_templ.go +++ b/html/components/posts/unsupported_templ.go @@ -12,11 +12,10 @@ import ( "bytes" "encoding/json" - "github.com/puregarlic/space/models" - "github.com/alecthomas/chroma/v2/formatters/html" "github.com/alecthomas/chroma/v2/lexers" "github.com/alecthomas/chroma/v2/styles" + "github.com/puregarlic/space/models" ) var style = styles.Get("rose-pine") @@ -92,7 +91,7 @@ func Unsupported(post *models.Post) templ.Component { templ_7745c5c3_Var2 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 1) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -122,7 +121,7 @@ func Unsupported(post *models.Post) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 2) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/html/components/sidebar.templ b/html/components/sidebar.templ new file mode 100644 index 0000000..26f24e5 --- /dev/null +++ b/html/components/sidebar.templ @@ -0,0 +1,12 @@ +package components + +templ Sidebar() { + +} diff --git a/html/components/sidebar_templ.go b/html/components/sidebar_templ.go new file mode 100644 index 0000000..54e7da7 --- /dev/null +++ b/html/components/sidebar_templ.go @@ -0,0 +1,35 @@ +// Code generated by templ - DO NOT EDIT. + +// templ: version: v0.2.747 +package components + +//lint:file-ignore SA4006 This context is only used if a nested component is present. + +import "github.com/a-h/templ" +import templruntime "github.com/a-h/templ/runtime" + +func Sidebar() templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var1 := templ.GetChildren(ctx) + if templ_7745c5c3_Var1 == nil { + templ_7745c5c3_Var1 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 1) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return templ_7745c5c3_Err + }) +} diff --git a/html/layouts/default.templ b/html/layouts/default.templ index afe92e7..54e60d0 100644 --- a/html/layouts/default.templ +++ b/html/layouts/default.templ @@ -1,37 +1,22 @@ package layouts -import "net/http" -import "github.com/puregarlic/space/storage" +import ( + "github.com/puregarlic/space/html/components" + "net/http" +) func RenderDefault(title string, page templ.Component) http.Handler { - rels := storage.GetRels() - document := Default(title, page, rels) + document := Default(title, page) - return templ.Handler(document) + return templ.Handler(document) } -templ Default(title string, body templ.Component, rels []*storage.RelEntry) { - - - - if len(title) > 0 { - {title} | puregarlic dot space - } else { - puregarlic dot space - } - - - - - - for _, rel := range rels { - - } - - - - - @body - - +templ Default(title string, body templ.Component) { + + + @components.Head(title) + + @body + + } diff --git a/html/layouts/default_templ.go b/html/layouts/default_templ.go index 7683106..829c549 100644 --- a/html/layouts/default_templ.go +++ b/html/layouts/default_templ.go @@ -8,17 +8,18 @@ package layouts import "github.com/a-h/templ" import templruntime "github.com/a-h/templ/runtime" -import "net/http" -import "github.com/puregarlic/space/storage" +import ( + "github.com/puregarlic/space/html/components" + "net/http" +) func RenderDefault(title string, page templ.Component) http.Handler { - rels := storage.GetRels() - document := Default(title, page, rels) + document := Default(title, page) return templ.Handler(document) } -func Default(title string, body templ.Component, rels []*storage.RelEntry) templ.Component { +func Default(title string, body templ.Component) templ.Component { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) @@ -36,71 +37,15 @@ func Default(title string, body templ.Component, rels []*storage.RelEntry) templ templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 1) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - if len(title) > 0 { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var2 string - templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(title) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `html/layouts/default.templ`, Line: 18, Col: 21} - } - _, 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(" | puregarlic dot space") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - } else { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("puregarlic dot space") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = components.Head(title).Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - for _, rel := range rels { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 2) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -108,7 +53,7 @@ func Default(title string, body templ.Component, rels []*storage.RelEntry) templ if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 3) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/html/layouts/sidebar.templ b/html/layouts/sidebar.templ new file mode 100644 index 0000000..29c0947 --- /dev/null +++ b/html/layouts/sidebar.templ @@ -0,0 +1,29 @@ +package layouts + +import ( + "github.com/puregarlic/space/html/components" + "net/http" +) + +func RenderWithSidebar(title string, body templ.Component) http.Handler { + page := WithSidebar(title, body) + + return templ.Handler(page) +} + +templ WithSidebar(title string, body templ.Component) { + + + @components.Head(title) + +
+ +
+ @body +
+
+ + +} diff --git a/html/layouts/sidebar_templ.go b/html/layouts/sidebar_templ.go new file mode 100644 index 0000000..1d4f16f --- /dev/null +++ b/html/layouts/sidebar_templ.go @@ -0,0 +1,70 @@ +// Code generated by templ - DO NOT EDIT. + +// templ: version: v0.2.747 +package layouts + +//lint:file-ignore SA4006 This context is only used if a nested component is present. + +import "github.com/a-h/templ" +import templruntime "github.com/a-h/templ/runtime" + +import ( + "github.com/puregarlic/space/html/components" + "net/http" +) + +func RenderWithSidebar(title string, body templ.Component) http.Handler { + page := WithSidebar(title, body) + + return templ.Handler(page) +} + +func WithSidebar(title string, body templ.Component) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var1 := templ.GetChildren(ctx) + if templ_7745c5c3_Var1 == nil { + templ_7745c5c3_Var1 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 1) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = components.Head(title).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 2) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = components.Sidebar().Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 3) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = body.Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 4) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return templ_7745c5c3_Err + }) +} diff --git a/html/pages/auth.templ b/html/pages/auth.templ index 439406e..d931555 100644 --- a/html/pages/auth.templ +++ b/html/pages/auth.templ @@ -1,72 +1,63 @@ package pages import ( - "strings" - "go.hacdias.com/indielib/indieauth" + "go.hacdias.com/indielib/indieauth" + "strings" ) -templ Auth( req *indieauth.AuthenticationRequest, app *indieauth.ApplicationMetadata, nonceId string, nonce string ) { -
-

authorize access to

-

puregarlic dot space

- -
- if app != nil { -
- if len(app.Logo) > 0 { - - } - -
-

{ app.Name }

- - if len(app.Author) > 0 { -

by {app.Author}

- } -
-
- } else { -

unidentified client

- } - -
-

Client ID

-

{ req.ClientID }

- -

Redirect URL

-

{ req.RedirectURI}

- -

Scopes

-
    - for _, scope := range req.Scopes { -
  • { scope }
  • - } -
-
-
- -
- - - - - - - - - // CSRF protections - - - - -
-
+templ Auth(req *indieauth.AuthenticationRequest, app *indieauth.ApplicationMetadata, nonceId string, nonce string) { +
+

authorize access to

+

puregarlic dot space

+
+ if app != nil { +
+ if len(app.Logo) > 0 { + + } +
+

{ app.Name }

+ if len(app.Author) > 0 { +

by { app.Author }

+ } +
+
+ } else { +

unidentified client

+ } +
+

Client ID

+

{ req.ClientID }

+

Redirect URL

+

{ req.RedirectURI }

+

Scopes

+
    + for _, scope := range req.Scopes { +
  • { scope }
  • + } +
+
+
+
+ + + + + + + + // CSRF protections + + + +
+
} diff --git a/html/pages/auth_templ.go b/html/pages/auth_templ.go index 3acff6b..1204754 100644 --- a/html/pages/auth_templ.go +++ b/html/pages/auth_templ.go @@ -31,234 +31,234 @@ func Auth(req *indieauth.AuthenticationRequest, app *indieauth.ApplicationMetada templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

authorize access to

puregarlic dot space

") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 1) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } if app != nil { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 2) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } if len(app.Logo) > 0 { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 4) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 5) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var3 string templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(app.Name) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `html/pages/auth.templ`, Line: 21, Col: 49} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `html/pages/auth.templ`, Line: 19, Col: 46} } _, 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("

") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 6) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } if len(app.Author) > 0 { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

by ") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 7) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var4 string templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(app.Author) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `html/pages/auth.templ`, Line: 24, Col: 56} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `html/pages/auth.templ`, Line: 21, Col: 52} } _, 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("

") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 8) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 9) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } else { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

unidentified client

") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 10) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

Client ID

") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 11) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var5 string templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(req.ClientID) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `html/pages/auth.templ`, Line: 34, Col: 103} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `html/pages/auth.templ`, Line: 30, Col: 101} } _, 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("

Redirect URL

") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 12) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var6 string templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(req.RedirectURI) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `html/pages/auth.templ`, Line: 37, Col: 95} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `html/pages/auth.templ`, Line: 32, Col: 93} } _, 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("

Scopes

    ") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 13) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } for _, scope := range req.Scopes { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
  • ") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 14) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var7 string templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(scope) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `html/pages/auth.templ`, Line: 42, Col: 63} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `html/pages/auth.templ`, Line: 36, Col: 59} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
  • ") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 15) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 24) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/html/pages/home.templ b/html/pages/home.templ index 548c29a..fb7b79f 100644 --- a/html/pages/home.templ +++ b/html/pages/home.templ @@ -1,37 +1,23 @@ package pages import ( - "github.com/puregarlic/space/models" - p "github.com/puregarlic/space/html/components/posts" + p "github.com/puregarlic/space/html/components/posts" + "github.com/puregarlic/space/models" ) templ Home(posts []*models.Post) { -
- -
-
    - if len(posts) > 0 { - for _, post := range posts { -
  • - @p.PostContent(post) - @p.PostFeedHeader(post) -
  • - } - } else { -
  • - intention-rich, content-poor -
  • - } -
-
-
- + } - diff --git a/html/pages/home_templ.go b/html/pages/home_templ.go index b0ca896..feb947a 100644 --- a/html/pages/home_templ.go +++ b/html/pages/home_templ.go @@ -31,36 +31,36 @@ func Home(posts []*models.Post) templ.Component { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
    ") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 1) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } if len(posts) > 0 { for _, post := range posts { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
  • ") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 2) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = p.PostContent(post).Render(ctx, templ_7745c5c3_Buffer) + templ_7745c5c3_Err = p.PostFeedHeader(post).Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = p.PostFeedHeader(post).Render(ctx, templ_7745c5c3_Buffer) + templ_7745c5c3_Err = p.PostContent(post).Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
  • ") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 3) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } } else { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
  • intention-rich, content-poor
  • ") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 4) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 5) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/html/pages/post.templ b/html/pages/post.templ index d1c90bc..c0836d7 100644 --- a/html/pages/post.templ +++ b/html/pages/post.templ @@ -1,61 +1,27 @@ package pages -import "github.com/puregarlic/space/models" -import "fmt" -import "encoding/json" -import "reflect" - -func printProperty(post *models.Post, name string) string { - props := make(map[string]any) - if err := json.Unmarshal(post.Properties, &props); err != nil { - panic(err) - } - - if val, ok := props[name]; ok { - tp := reflect.TypeOf(val) - switch tp.Kind() { - default: - return fmt.Sprint(val) - case reflect.Slice: - str := "" - for _, v := range val.([]any) { - str = str + fmt.Sprint(v) - } - - return str - } - - } - - return "" -} - -func printPost(post *models.Post) string { - out, err := json.Marshal(post) - - if (err != nil) { - panic (err) - } - - return fmt.Sprint(string(out)) -} +import ( + "github.com/puregarlic/space/html/components/posts" + "github.com/puregarlic/space/models" +) templ Post(post *models.Post) { - - - - Post | Micropub and IndieAuth Server Demo - - -
-

{ printProperty(post, "name") }

-

{ printProperty(post, "content") }

- -

Stored Microformats

- -
{ printPost(post) }
-
-
- - +
+ + + + + back to home + +
+ @posts.PostContent(post) +
+ @posts.PostDetails(post) +
+ interactions not implemented yet + + + +
+
} diff --git a/html/pages/post_templ.go b/html/pages/post_templ.go index 12d5593..d7000d6 100644 --- a/html/pages/post_templ.go +++ b/html/pages/post_templ.go @@ -8,45 +8,10 @@ package pages import "github.com/a-h/templ" import templruntime "github.com/a-h/templ/runtime" -import "github.com/puregarlic/space/models" -import "fmt" -import "encoding/json" -import "reflect" - -func printProperty(post *models.Post, name string) string { - props := make(map[string]any) - if err := json.Unmarshal(post.Properties, &props); err != nil { - panic(err) - } - - if val, ok := props[name]; ok { - tp := reflect.TypeOf(val) - switch tp.Kind() { - default: - return fmt.Sprint(val) - case reflect.Slice: - str := "" - for _, v := range val.([]any) { - str = str + fmt.Sprint(v) - } - - return str - } - - } - - return "" -} - -func printPost(post *models.Post) string { - out, err := json.Marshal(post) - - if err != nil { - panic(err) - } - - return fmt.Sprint(string(out)) -} +import ( + "github.com/puregarlic/space/html/components/posts" + "github.com/puregarlic/space/models" +) func Post(post *models.Post) templ.Component { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { @@ -66,68 +31,23 @@ func Post(post *models.Post) templ.Component { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Post | Micropub and IndieAuth Server Demo") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 1) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var2 = []any{post.Type} - templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var2...) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 2) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var4 string - templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(printProperty(post, "name")) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `html/pages/post.templ`, Line: 51, Col: 56} - } - _, 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("

") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var5 string - templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(printProperty(post, "content")) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `html/pages/post.templ`, Line: 52, Col: 61} - } - _, 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("

Stored Microformats

")
-		if templ_7745c5c3_Err != nil {
-			return templ_7745c5c3_Err
-		}
-		var templ_7745c5c3_Var6 string
-		templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(printPost(post))
-		if templ_7745c5c3_Err != nil {
-			return templ.Error{Err: templ_7745c5c3_Err, FileName: `html/pages/post.templ`, Line: 56, Col: 32}
-		}
-		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
+		templ_7745c5c3_Err = posts.PostDetails(post).Render(ctx, templ_7745c5c3_Buffer)
 		if templ_7745c5c3_Err != nil {
 			return templ_7745c5c3_Err
 		}
-		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 3) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/models/post.go b/models/post.go index 24d8316..5bd8017 100644 --- a/models/post.go +++ b/models/post.go @@ -19,3 +19,7 @@ type Post struct { UpdatedAt time.Time DeletedAt gorm.DeletedAt `gorm:"index"` } + +func (p *Post) Timestamp() string { + return p.CreatedAt.Format("01/02/2006 at 3:04 PM") +} -- 2.51.2