An experimental IndieWeb site built in Go.
1// Code generated by templ - DO NOT EDIT.
2
3// templ: version: v0.2.747
4package posts
5
6//lint:file-ignore SA4006 This context is only used if a nested component is present.
7
8import "github.com/a-h/templ"
9import templruntime "github.com/a-h/templ/runtime"
10
11import (
12 "encoding/json"
13 "fmt"
14
15 "github.com/puregarlic/space/models"
16 "github.com/samber/lo"
17 "go.hacdias.com/indielib/microformats"
18)
19
20var ImplementedPostTypes = []microformats.Type{
21 microformats.TypeNote,
22 microformats.TypePhoto,
23}
24
25func GetPostJSONProperty(post *models.Post, name string) []string {
26 var tmp map[string]any
27 if err := json.Unmarshal(post.Properties, &tmp); err != nil {
28 panic(err)
29 }
30
31 prop, ok := tmp[name]
32 if !ok {
33 return []string{""}
34 }
35
36 var out []string
37 for _, val := range prop.([]any) {
38 out = append(out, val.(string))
39 }
40
41 return out
42}
43
44func formatPostTypeName(mfType microformats.Type) string {
45 has := lo.ContainsBy(ImplementedPostTypes, func(postType microformats.Type) bool {
46 return postType == mfType
47 })
48
49 if has {
50 return string(mfType)
51 } else {
52 return fmt.Sprintf("%s (oops!)", string(mfType))
53 }
54}
55
56func PostFeedHeader(post *models.Post) templ.Component {
57 return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
58 templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
59 templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
60 if !templ_7745c5c3_IsBuffer {
61 defer func() {
62 templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
63 if templ_7745c5c3_Err == nil {
64 templ_7745c5c3_Err = templ_7745c5c3_BufErr
65 }
66 }()
67 }
68 ctx = templ.InitializeContext(ctx)
69 templ_7745c5c3_Var1 := templ.GetChildren(ctx)
70 if templ_7745c5c3_Var1 == nil {
71 templ_7745c5c3_Var1 = templ.NopComponent
72 }
73 ctx = templ.ClearChildren(ctx)
74 _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"px-3 py-2 bg-surface text-xs text-muted flex items-center justify-between rounded-t border-2 border-b-0 border-overlay\"><p>")
75 if templ_7745c5c3_Err != nil {
76 return templ_7745c5c3_Err
77 }
78 var templ_7745c5c3_Var2 string
79 templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(post.Timestamp())
80 if templ_7745c5c3_Err != nil {
81 return templ.Error{Err: templ_7745c5c3_Err, FileName: `html/components/posts/post.templ`, Line: 50, Col: 23}
82 }
83 _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2))
84 if templ_7745c5c3_Err != nil {
85 return templ_7745c5c3_Err
86 }
87 _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</p><p class=\"flex gap-1.5\">")
88 if templ_7745c5c3_Err != nil {
89 return templ_7745c5c3_Err
90 }
91 var templ_7745c5c3_Var3 string
92 templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(formatPostTypeName(post.MicroformatType))
93 if templ_7745c5c3_Err != nil {
94 return templ.Error{Err: templ_7745c5c3_Err, FileName: `html/components/posts/post.templ`, Line: 52, Col: 45}
95 }
96 _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
97 if templ_7745c5c3_Err != nil {
98 return templ_7745c5c3_Err
99 }
100 _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" <span class=\"text-muted/40\">•</span> <a class=\"hover:underline hover:text-iris flex items-center gap-1 transition\" target=\"_blank\" rel=\"noopener noreferrer\" href=\"")
101 if templ_7745c5c3_Err != nil {
102 return templ_7745c5c3_Err
103 }
104 var templ_7745c5c3_Var4 templ.SafeURL = templ.URL("/posts/" + post.ID.String())
105 _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(string(templ_7745c5c3_Var4)))
106 if templ_7745c5c3_Err != nil {
107 return templ_7745c5c3_Err
108 }
109 _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\">open <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 16 16\" fill=\"currentColor\" class=\"size-4 -mt-px\"><path d=\"M6.22 8.72a.75.75 0 0 0 1.06 1.06l5.22-5.22v1.69a.75.75 0 0 0 1.5 0v-3.5a.75.75 0 0 0-.75-.75h-3.5a.75.75 0 0 0 0 1.5h1.69L6.22 8.72Z\"></path> <path d=\"M3.5 6.75c0-.69.56-1.25 1.25-1.25H7A.75.75 0 0 0 7 4H4.75A2.75 2.75 0 0 0 2 6.75v4.5A2.75 2.75 0 0 0 4.75 14h4.5A2.75 2.75 0 0 0 12 11.25V9a.75.75 0 0 0-1.5 0v2.25c0 .69-.56 1.25-1.25 1.25h-4.5c-.69 0-1.25-.56-1.25-1.25v-4.5Z\"></path></svg></a></p></div>")
110 if templ_7745c5c3_Err != nil {
111 return templ_7745c5c3_Err
112 }
113 return templ_7745c5c3_Err
114 })
115}
116
117func PostDetails(post *models.Post) templ.Component {
118 return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
119 templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
120 templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
121 if !templ_7745c5c3_IsBuffer {
122 defer func() {
123 templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
124 if templ_7745c5c3_Err == nil {
125 templ_7745c5c3_Err = templ_7745c5c3_BufErr
126 }
127 }()
128 }
129 ctx = templ.InitializeContext(ctx)
130 templ_7745c5c3_Var5 := templ.GetChildren(ctx)
131 if templ_7745c5c3_Var5 == nil {
132 templ_7745c5c3_Var5 = templ.NopComponent
133 }
134 ctx = templ.ClearChildren(ctx)
135 _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<dl class=\"grid md:grid-cols-2 gap-4\"><div><dt class=\"mb-1 text-sm text-muted\">Posted At</dt><dd class=\"text-subtle\">")
136 if templ_7745c5c3_Err != nil {
137 return templ_7745c5c3_Err
138 }
139 var templ_7745c5c3_Var6 string
140 templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(post.Timestamp())
141 if templ_7745c5c3_Err != nil {
142 return templ.Error{Err: templ_7745c5c3_Err, FileName: `html/components/posts/post.templ`, Line: 74, Col: 45}
143 }
144 _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
145 if templ_7745c5c3_Err != nil {
146 return templ_7745c5c3_Err
147 }
148 _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</dd></div><div><dt class=\"mb-1 text-sm text-muted\">Post Type</dt><dd class=\"text-subtle\">")
149 if templ_7745c5c3_Err != nil {
150 return templ_7745c5c3_Err
151 }
152 var templ_7745c5c3_Var7 string
153 templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(string(post.MicroformatType))
154 if templ_7745c5c3_Err != nil {
155 return templ.Error{Err: templ_7745c5c3_Err, FileName: `html/components/posts/post.templ`, Line: 78, Col: 57}
156 }
157 _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
158 if templ_7745c5c3_Err != nil {
159 return templ_7745c5c3_Err
160 }
161 _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</dd></div></dl>")
162 if templ_7745c5c3_Err != nil {
163 return templ_7745c5c3_Err
164 }
165 return templ_7745c5c3_Err
166 })
167}
168
169func PostContent(post *models.Post) templ.Component {
170 return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
171 templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
172 templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
173 if !templ_7745c5c3_IsBuffer {
174 defer func() {
175 templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
176 if templ_7745c5c3_Err == nil {
177 templ_7745c5c3_Err = templ_7745c5c3_BufErr
178 }
179 }()
180 }
181 ctx = templ.InitializeContext(ctx)
182 templ_7745c5c3_Var8 := templ.GetChildren(ctx)
183 if templ_7745c5c3_Var8 == nil {
184 templ_7745c5c3_Var8 = templ.NopComponent
185 }
186 ctx = templ.ClearChildren(ctx)
187 switch post.MicroformatType {
188 case microformats.TypePhoto:
189 templ_7745c5c3_Err = Photo(post).Render(ctx, templ_7745c5c3_Buffer)
190 if templ_7745c5c3_Err != nil {
191 return templ_7745c5c3_Err
192 }
193 case microformats.TypeNote:
194 templ_7745c5c3_Err = Note(post).Render(ctx, templ_7745c5c3_Buffer)
195 if templ_7745c5c3_Err != nil {
196 return templ_7745c5c3_Err
197 }
198 default:
199 templ_7745c5c3_Err = Unsupported(post).Render(ctx, templ_7745c5c3_Buffer)
200 if templ_7745c5c3_Err != nil {
201 return templ_7745c5c3_Err
202 }
203 }
204 return templ_7745c5c3_Err
205 })
206}