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 "bytes"
13 "encoding/json"
14
15 "github.com/alecthomas/chroma/v2/formatters/html"
16 "github.com/alecthomas/chroma/v2/lexers"
17 "github.com/alecthomas/chroma/v2/styles"
18 "github.com/puregarlic/space/models"
19)
20
21var style = styles.Get("rose-pine")
22var lexer = lexers.Get("json")
23var formatter = html.New(html.TabWidth(2), html.WithClasses(true))
24
25var dedupeSyntaxStyles = templ.NewOnceHandle()
26
27func renderPostAsJSON(post *models.Post) string {
28 contents, err := json.MarshalIndent(post.Properties, "", " ")
29 if err != nil {
30 panic(err)
31 }
32
33 iterator, err := lexer.Tokenise(nil, string(contents))
34
35 var buf bytes.Buffer
36 formatter.Format(&buf, style, iterator)
37
38 return buf.String()
39}
40
41func generateSyntaxClassNames() string {
42 var buf bytes.Buffer
43 if err := formatter.WriteCSS(&buf, style); err != nil {
44 panic(err)
45 }
46
47 return "<style>" + buf.String() + "</style>"
48}
49
50func syntaxStyleTag() templ.Component {
51 return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
52 templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
53 templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
54 if !templ_7745c5c3_IsBuffer {
55 defer func() {
56 templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
57 if templ_7745c5c3_Err == nil {
58 templ_7745c5c3_Err = templ_7745c5c3_BufErr
59 }
60 }()
61 }
62 ctx = templ.InitializeContext(ctx)
63 templ_7745c5c3_Var1 := templ.GetChildren(ctx)
64 if templ_7745c5c3_Var1 == nil {
65 templ_7745c5c3_Var1 = templ.NopComponent
66 }
67 ctx = templ.ClearChildren(ctx)
68 templ_7745c5c3_Err = templ.Raw(generateSyntaxClassNames()).Render(ctx, templ_7745c5c3_Buffer)
69 if templ_7745c5c3_Err != nil {
70 return templ_7745c5c3_Err
71 }
72 return templ_7745c5c3_Err
73 })
74}
75
76func Unsupported(post *models.Post) templ.Component {
77 return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
78 templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
79 templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
80 if !templ_7745c5c3_IsBuffer {
81 defer func() {
82 templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
83 if templ_7745c5c3_Err == nil {
84 templ_7745c5c3_Err = templ_7745c5c3_BufErr
85 }
86 }()
87 }
88 ctx = templ.InitializeContext(ctx)
89 templ_7745c5c3_Var2 := templ.GetChildren(ctx)
90 if templ_7745c5c3_Var2 == nil {
91 templ_7745c5c3_Var2 = templ.NopComponent
92 }
93 ctx = templ.ClearChildren(ctx)
94 _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"block p-4 bg-base overflow-x-scroll min-w-0 first:rounded-t last:rounded-b border-2 border-overlay\">")
95 if templ_7745c5c3_Err != nil {
96 return templ_7745c5c3_Err
97 }
98 templ_7745c5c3_Var3 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
99 templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
100 templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
101 if !templ_7745c5c3_IsBuffer {
102 defer func() {
103 templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
104 if templ_7745c5c3_Err == nil {
105 templ_7745c5c3_Err = templ_7745c5c3_BufErr
106 }
107 }()
108 }
109 ctx = templ.InitializeContext(ctx)
110 templ_7745c5c3_Err = syntaxStyleTag().Render(ctx, templ_7745c5c3_Buffer)
111 if templ_7745c5c3_Err != nil {
112 return templ_7745c5c3_Err
113 }
114 return templ_7745c5c3_Err
115 })
116 templ_7745c5c3_Err = dedupeSyntaxStyles.Once().Render(templ.WithChildren(ctx, templ_7745c5c3_Var3), templ_7745c5c3_Buffer)
117 if templ_7745c5c3_Err != nil {
118 return templ_7745c5c3_Err
119 }
120 templ_7745c5c3_Err = templ.Raw(renderPostAsJSON(post)).Render(ctx, templ_7745c5c3_Buffer)
121 if templ_7745c5c3_Err != nil {
122 return templ_7745c5c3_Err
123 }
124 _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div>")
125 if templ_7745c5c3_Err != nil {
126 return templ_7745c5c3_Err
127 }
128 return templ_7745c5c3_Err
129 })
130}