+2
go.mod
+2
go.mod
···
5
5
require (
6
6
codeberg.org/gruf/go-ulid v1.1.0
7
7
github.com/aidarkhanov/nanoid v1.0.8
8
+
github.com/alecthomas/chroma/v2 v2.14.0
8
9
github.com/aws/aws-sdk-go-v2 v1.30.3
9
10
github.com/glebarez/sqlite v1.11.0
10
11
github.com/go-chi/cors v1.2.1
···
34
35
github.com/aws/aws-sdk-go-v2/service/sts v1.30.3 // indirect
35
36
github.com/aws/smithy-go v1.20.3 // indirect
36
37
github.com/cespare/xxhash/v2 v2.3.0 // indirect
38
+
github.com/dlclark/regexp2 v1.11.0 // indirect
37
39
github.com/dustin/go-humanize v1.0.1 // indirect
38
40
github.com/glebarez/go-sqlite v1.21.2 // indirect
39
41
github.com/go-sql-driver/mysql v1.8.1 // indirect
+10
go.sum
+10
go.sum
···
6
6
github.com/a-h/templ v0.2.747/go.mod h1:69ObQIbrcuwPCU32ohNaWce3Cb7qM5GMiqN1K+2yop4=
7
7
github.com/aidarkhanov/nanoid v1.0.8 h1:yxyJkgsEDFXP7+97vc6JevMcjyb03Zw+/9fqhlVXBXA=
8
8
github.com/aidarkhanov/nanoid v1.0.8/go.mod h1:vadfZHT+m4uDhttg0yY4wW3GKtl2T6i4d2Age+45pYk=
9
+
github.com/alecthomas/assert/v2 v2.7.0 h1:QtqSACNS3tF7oasA8CU6A6sXZSBDqnm7RfpLl9bZqbE=
10
+
github.com/alecthomas/assert/v2 v2.7.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
11
+
github.com/alecthomas/chroma/v2 v2.14.0 h1:R3+wzpnUArGcQz7fCETQBzO5n9IMNi13iIs46aU4V9E=
12
+
github.com/alecthomas/chroma/v2 v2.14.0/go.mod h1:QolEbTfmUHIMVpBqxeDnNBj2uoeI4EbYP4i6n68SG4I=
13
+
github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc=
14
+
github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
9
15
github.com/andybalholm/cascadia v1.3.1/go.mod h1:R4bJ1UQfqADjvDa4P6HZHLh/3OxWWEqc0Sk8XGwHqvA=
10
16
github.com/aws/aws-sdk-go-v2 v1.30.3 h1:jUeBtG0Ih+ZIFH0F4UkmL9w3cSpaMv9tYYDbzILP8dY=
11
17
github.com/aws/aws-sdk-go-v2 v1.30.3/go.mod h1:nIQjQVp5sfpQcTc9mPSr1B0PaWK5ByX9MOoDadSN4lc=
···
47
53
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
48
54
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
49
55
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
56
+
github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxKI=
57
+
github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
50
58
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
51
59
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
52
60
github.com/glebarez/go-sqlite v1.21.2 h1:3a6LFC4sKahUunAmynQKLZceZCOzUthkRkEAl9gAXWo=
···
77
85
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
78
86
github.com/h2non/filetype v1.1.3 h1:FKkx9QbD7HR/zjK1Ia5XiBsq9zdLi5Kf3zGyFTAFkGg=
79
87
github.com/h2non/filetype v1.1.3/go.mod h1:319b3zT68BvV+WRj7cwy856M2ehB3HqNOt6sy1HndBY=
88
+
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
89
+
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
80
90
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
81
91
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
82
92
github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 h1:L0QtFUgDarD7Fpv9jeVMgy/+Ec0mtnmYuImjTz6dtDA=
+51
-28
html/pages/home.templ
+51
-28
html/pages/home.templ
···
1
1
package pages
2
2
3
-
import "github.com/puregarlic/space/models"
4
-
import "fmt"
5
-
import "encoding/json"
3
+
import (
4
+
"encoding/json"
5
+
"bytes"
6
6
7
-
func getPostPropertyValue(post *models.Post, name string) any {
8
-
props := make(map[string]any)
9
-
if err := json.Unmarshal(post.Properties, &props); err != nil {
7
+
"github.com/puregarlic/space/models"
8
+
"github.com/alecthomas/chroma/v2/formatters/html"
9
+
"github.com/alecthomas/chroma/v2/styles"
10
+
"github.com/alecthomas/chroma/v2/lexers"
11
+
)
12
+
13
+
func formatUnknownPost(post *models.Post) string {
14
+
style := styles.Get("rose-pine")
15
+
lexer := lexers.Get("json")
16
+
formatter := html.New(
17
+
html.TabWidth(2),
18
+
)
19
+
20
+
contents, err := json.MarshalIndent(post.Properties, "", " ")
21
+
if err != nil {
10
22
panic(err)
11
23
}
12
24
13
-
return props[name]
25
+
iterator, err := lexer.Tokenise(nil, string(contents))
26
+
27
+
var buf bytes.Buffer
28
+
formatter.Format(&buf, style, iterator)
29
+
30
+
return buf.String()
14
31
}
15
32
16
33
templ Home(posts []*models.Post) {
17
-
<!DOCTYPE html>
18
-
<html>
19
-
<head>
20
-
<title>Micropub and IndieAuth Server Demo</title>
21
-
<link rel="authorization_endpoint" href="/authorization">
22
-
<link rel="token_endpoint" href="/token">
23
-
<link rel="micropub" href="/micropub">
24
-
25
-
// <link rel="stylesheet" href="/static/styles.css" />
26
-
</head>
27
-
<body>
28
-
<h1>Micropub and IndieAuth Server Demo</h1>
29
-
30
-
<h2>Posts</h2>
31
-
32
-
<p>You can create posts using a Micropub client.</p>
33
-
<ul>
34
-
for _, post := range posts {
35
-
<li><a href={ templ.URL("/posts/" + post.ID.String()) }>{ post.ID.String() }</a> - { fmt.Sprint(getPostPropertyValue(post, "content")) }</li>
34
+
<div class="px-4 py-8 md:py-20 md:mx-auto md:max-w-screen-lg grid md:grid-cols-[1fr_2fr] gap-12 md:gap-16">
35
+
<aside class="min-w-0">
36
+
<h1 class="font-extrabold">puregarlic dot space</h1>
37
+
<p class="font-light mt-3 text-sm text-subtle">this space is mine, it was <a class="underline" href="https://github.com/puregarlic/space">made by me</a>!</p>
38
+
</aside>
39
+
<main class="min-w-0">
40
+
<ul class="flex flex-col gap-6">
41
+
if len(posts) > 0 {
42
+
for _, post := range posts {
43
+
<li>
44
+
<div class="mb-1 flex items-center justify-between text-muted text-xs">
45
+
<p>{ post.CreatedAt.Format("01/02/2006 at 3:04 PM") }</p>
46
+
<p>oops, unimplemented!</p>
47
+
</div>
48
+
<a href={ templ.URL("/posts/" + post.ID.String()) } class="block p-4 bg-base overflow-x-scroll min-w-0">
49
+
@templ.Raw(formatUnknownPost(post))
50
+
</a>
51
+
</li>
52
+
}
53
+
} else {
54
+
<li class="text-highlightLow italic font-light bg-base p-4 text-center">
55
+
intention rich, content poor
56
+
</li>
36
57
}
37
58
</ul>
38
-
</body>
39
-
</html>
59
+
</main>
60
+
</div>
61
+
40
62
}
63
+
+64
-45
html/pages/home_templ.go
+64
-45
html/pages/home_templ.go
···
8
8
import "github.com/a-h/templ"
9
9
import templruntime "github.com/a-h/templ/runtime"
10
10
11
-
import "github.com/puregarlic/space/models"
12
-
import "fmt"
13
-
import "encoding/json"
11
+
import (
12
+
"bytes"
13
+
"encoding/json"
14
14
15
-
func getPostPropertyValue(post *models.Post, name string) any {
16
-
props := make(map[string]any)
17
-
if err := json.Unmarshal(post.Properties, &props); err != nil {
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
+
21
+
func formatUnknownPost(post *models.Post) string {
22
+
style := styles.Get("rose-pine")
23
+
lexer := lexers.Get("json")
24
+
formatter := html.New(
25
+
html.TabWidth(2),
26
+
)
27
+
28
+
contents, err := json.MarshalIndent(post.Properties, "", " ")
29
+
if err != nil {
18
30
panic(err)
19
31
}
20
32
21
-
return props[name]
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()
22
39
}
23
40
24
41
func Home(posts []*models.Post) templ.Component {
···
39
56
templ_7745c5c3_Var1 = templ.NopComponent
40
57
}
41
58
ctx = templ.ClearChildren(ctx)
42
-
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<!doctype html><html><head><title>Micropub and IndieAuth Server Demo</title><link rel=\"authorization_endpoint\" href=\"/authorization\"><link rel=\"token_endpoint\" href=\"/token\"><link rel=\"micropub\" href=\"/micropub\"></head><body><h1>Micropub and IndieAuth Server Demo</h1><h2>Posts</h2><p>You can create posts using a Micropub client.</p><ul>")
59
+
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"px-4 py-8 md:py-20 md:mx-auto md:max-w-screen-lg grid md:grid-cols-[1fr_2fr] gap-12 md:gap-16\"><aside class=\"min-w-0\"><h1 class=\"font-extrabold\">puregarlic dot space</h1><p class=\"font-light mt-3 text-sm text-subtle\">this space is mine, it was <a class=\"underline\" href=\"https://github.com/puregarlic/space\">made by me</a>!</p></aside><main class=\"min-w-0\"><ul class=\"flex flex-col gap-6\">")
43
60
if templ_7745c5c3_Err != nil {
44
61
return templ_7745c5c3_Err
45
62
}
46
-
for _, post := range posts {
47
-
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<li><a href=\"")
48
-
if templ_7745c5c3_Err != nil {
49
-
return templ_7745c5c3_Err
50
-
}
51
-
var templ_7745c5c3_Var2 templ.SafeURL = templ.URL("/posts/" + post.ID.String())
52
-
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(string(templ_7745c5c3_Var2)))
53
-
if templ_7745c5c3_Err != nil {
54
-
return templ_7745c5c3_Err
55
-
}
56
-
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\">")
57
-
if templ_7745c5c3_Err != nil {
58
-
return templ_7745c5c3_Err
59
-
}
60
-
var templ_7745c5c3_Var3 string
61
-
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(post.ID.String())
62
-
if templ_7745c5c3_Err != nil {
63
-
return templ.Error{Err: templ_7745c5c3_Err, FileName: `html/pages/home.templ`, Line: 35, Col: 82}
64
-
}
65
-
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
66
-
if templ_7745c5c3_Err != nil {
67
-
return templ_7745c5c3_Err
68
-
}
69
-
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</a> - ")
70
-
if templ_7745c5c3_Err != nil {
71
-
return templ_7745c5c3_Err
72
-
}
73
-
var templ_7745c5c3_Var4 string
74
-
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprint(getPostPropertyValue(post, "content")))
75
-
if templ_7745c5c3_Err != nil {
76
-
return templ.Error{Err: templ_7745c5c3_Err, FileName: `html/pages/home.templ`, Line: 35, Col: 142}
63
+
if len(posts) > 0 {
64
+
for _, post := range posts {
65
+
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<li><div class=\"mb-1 flex items-center justify-between text-muted text-xs\"><p>")
66
+
if templ_7745c5c3_Err != nil {
67
+
return templ_7745c5c3_Err
68
+
}
69
+
var templ_7745c5c3_Var2 string
70
+
templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(post.CreatedAt.Format("01/02/2006 at 3:04 PM"))
71
+
if templ_7745c5c3_Err != nil {
72
+
return templ.Error{Err: templ_7745c5c3_Err, FileName: `html/pages/home.templ`, Line: 45, Col: 64}
73
+
}
74
+
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2))
75
+
if templ_7745c5c3_Err != nil {
76
+
return templ_7745c5c3_Err
77
+
}
78
+
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</p><p>oops, unimplemented!</p></div><a href=\"")
79
+
if templ_7745c5c3_Err != nil {
80
+
return templ_7745c5c3_Err
81
+
}
82
+
var templ_7745c5c3_Var3 templ.SafeURL = templ.URL("/posts/" + post.ID.String())
83
+
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(string(templ_7745c5c3_Var3)))
84
+
if templ_7745c5c3_Err != nil {
85
+
return templ_7745c5c3_Err
86
+
}
87
+
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" class=\"block p-4 bg-base overflow-x-scroll min-w-0\">")
88
+
if templ_7745c5c3_Err != nil {
89
+
return templ_7745c5c3_Err
90
+
}
91
+
templ_7745c5c3_Err = templ.Raw(formatUnknownPost(post)).Render(ctx, templ_7745c5c3_Buffer)
92
+
if templ_7745c5c3_Err != nil {
93
+
return templ_7745c5c3_Err
94
+
}
95
+
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</a></li>")
96
+
if templ_7745c5c3_Err != nil {
97
+
return templ_7745c5c3_Err
98
+
}
77
99
}
78
-
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
79
-
if templ_7745c5c3_Err != nil {
80
-
return templ_7745c5c3_Err
81
-
}
82
-
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</li>")
100
+
} else {
101
+
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<li class=\"text-highlightLow italic font-light bg-base p-4 text-center\">intention rich, content poor</li>")
83
102
if templ_7745c5c3_Err != nil {
84
103
return templ_7745c5c3_Err
85
104
}
86
105
}
87
-
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</ul></body></html>")
106
+
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</ul></main></div>")
88
107
if templ_7745c5c3_Err != nil {
89
108
return templ_7745c5c3_Err
90
109
}