1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
|
diff --git a/pkg/apps/prose/api.go b/pkg/apps/prose/api.go
index 7225ca6..92be799 100644
--- a/pkg/apps/prose/api.go
+++ b/pkg/apps/prose/api.go
@@ -90,6 +90,7 @@ type PostPageData struct {
Diff template.HTML
UpdatedAtISO string
UpdatedAt string
+ List *shared.ListParsedText
}
type HeaderTxt struct {
@@ -427,22 +428,38 @@ func postHandler(w http.ResponseWriter, r *http.Request) {
post, err := dbpool.FindPostWithSlug(slug, user.ID, cfg.Space)
if err == nil {
logger.Info("post found", "id", post.ID, "filename", post.FileSize)
- parsedText, err := shared.ParseText(post.Text)
- if err != nil {
- logger.Error("find post with slug", "err", err.Error())
- }
+ ext := filepath.Ext(post.Filename)
+ contents := template.HTML("")
+ tags := []string{}
+ unlisted := false
+ var list *shared.ListParsedText
+
+ switch ext {
+ case ".lxt":
+ list = shared.ListParseText(post.Text)
+ tags = list.Tags
+ if post.Hidden || post.PublishAt.After(time.Now()) {
+ unlisted = true
+ }
+ case ".md":
+ parsedText, err := shared.ParseText(post.Text)
+ if err != nil {
+ logger.Error("could not parse md text", "err", err.Error())
+ }
- if parsedText.Image != "" {
- ogImage = parsedText.Image
- }
+ if parsedText.Image != "" {
+ ogImage = parsedText.Image
+ }
- if parsedText.ImageCard != "" {
- ogImageCard = parsedText.ImageCard
- }
+ if parsedText.ImageCard != "" {
+ ogImageCard = parsedText.ImageCard
+ }
+ tags = parsedText.Tags
- unlisted := false
- if post.Hidden || post.PublishAt.After(time.Now()) {
- unlisted = true
+ if post.Hidden || post.PublishAt.After(time.Now()) {
+ unlisted = true
+ }
+ contents = template.HTML(parsedText.Html)
}
data = PostPageData{
@@ -459,10 +476,10 @@ func postHandler(w http.ResponseWriter, r *http.Request) {
UpdatedAtISO: post.UpdatedAt.Format(time.RFC3339),
Username: username,
BlogName: blogName,
- Contents: template.HTML(parsedText.Html),
+ Contents: contents,
HasCSS: hasCSS,
CssURL: template.URL(cfg.CssURL(username)),
- Tags: parsedText.Tags,
+ Tags: tags,
Image: template.URL(ogImage),
ImageCard: ogImageCard,
Favicon: template.URL(favicon),
@@ -470,6 +487,7 @@ func postHandler(w http.ResponseWriter, r *http.Request) {
Unlisted: unlisted,
Diff: template.HTML(diff),
WithStyles: withStyles,
+ List: list,
}
} else {
logger.Info("post not found")
@@ -522,6 +540,7 @@ func postHandler(w http.ResponseWriter, r *http.Request) {
}
ts, err := shared.RenderTemplate(cfg, []string{
+ cfg.StaticPath("html/list.partial.tmpl"),
cfg.StaticPath("html/post.page.tmpl"),
})
@@ -651,7 +670,10 @@ func rssBlogHandler(w http.ResponseWriter, r *http.Request) {
return
}
- ts, err := template.ParseFiles(cfg.StaticPath("html/rss.page.tmpl"))
+ ts, err := template.New("rss.page.tmpl").Funcs(shared.FuncMap).ParseFiles(
+ cfg.StaticPath("html/list.partial.tmpl"),
+ cfg.StaticPath("html/rss.page.tmpl"),
+ )
if err != nil {
logger.Error("template parse file", "err", err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
@@ -700,27 +722,48 @@ func rssBlogHandler(w http.ResponseWriter, r *http.Request) {
if slices.Contains(cfg.HiddenPosts, post.Filename) {
continue
}
- parsed, err := shared.ParseText(post.Text)
- if err != nil {
- logger.Error("parse post text", "err", err.Error())
- }
- footer, err := dbpool.FindPostWithFilename("_footer.md", user.ID, cfg.Space)
- var footerHTML string
- if err == nil {
- footerParsed, err := shared.ParseText(footer.Text)
+ content := ""
+ ext := filepath.Ext(post.Filename)
+ fmt.Println("HERE", post.Filename, ext)
+ switch ext {
+ case ".md":
+ parsed, err := shared.ParseText(post.Text)
if err != nil {
- logger.Error("parse footer text", "err", err.Error())
+ logger.Error("parse post text", "err", err.Error())
}
- footerHTML = footerParsed.Html
- }
- var tpl bytes.Buffer
- data := &PostPageData{
- Contents: template.HTML(parsed.Html + footerHTML),
- }
- if err := ts.Execute(&tpl, data); err != nil {
- continue
+ footer, err := dbpool.FindPostWithFilename("_footer.md", user.ID, cfg.Space)
+ var footerHTML string
+ if err == nil {
+ footerParsed, err := shared.ParseText(footer.Text)
+ if err != nil {
+ logger.Error("parse footer text", "err", err.Error())
+ }
+ footerHTML = footerParsed.Html
+ }
+
+ var tpl bytes.Buffer
+ data := &PostPageData{
+ Contents: template.HTML(parsed.Html + footerHTML),
+ }
+ if err := ts.Execute(&tpl, data); err != nil {
+ logger.Error("md template", "err", err)
+ continue
+ }
+ content = tpl.String()
+ case ".lxt":
+ parsed := shared.ListParseText(post.Text)
+ var tpl bytes.Buffer
+ data := &PostPageData{
+ List: parsed,
+ }
+ if err := ts.Execute(&tpl, data); err != nil {
+ logger.Error("lxt template", "err", err)
+ continue
+ }
+ content = tpl.String()
+
}
realUrl := cfg.FullPostURL(curl, post.Username, post.Slug)
@@ -730,7 +773,7 @@ func rssBlogHandler(w http.ResponseWriter, r *http.Request) {
Id: feedId,
Title: utils.FilenameToTitle(post.Filename, post.Title),
Link: &feeds.Link{Href: realUrl},
- Content: tpl.String(),
+ Content: content,
Updated: *post.PublishAt,
Created: *post.PublishAt,
Description: post.Description,
@@ -769,7 +812,10 @@ func rssHandler(w http.ResponseWriter, r *http.Request) {
return
}
- ts, err := template.ParseFiles(cfg.StaticPath("html/rss.page.tmpl"))
+ ts, err := template.New("rss.page.tmpl").Funcs(shared.FuncMap).ParseFiles(
+ cfg.StaticPath("html/list.partial.tmpl"),
+ cfg.StaticPath("html/rss.page.tmpl"),
+ )
if err != nil {
logger.Error("template parse file", "err", err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
@@ -788,17 +834,34 @@ func rssHandler(w http.ResponseWriter, r *http.Request) {
var feedItems []*feeds.Item
for _, post := range pager.Data {
- parsed, err := shared.ParseText(post.Text)
- if err != nil {
- logger.Error(err.Error())
- }
+ content := ""
+ ext := filepath.Ext(post.Filename)
+ switch ext {
+ case ".md":
+ parsed, err := shared.ParseText(post.Text)
+ if err != nil {
+ logger.Error(err.Error())
+ }
+
+ var tpl bytes.Buffer
+ data := &PostPageData{
+ Contents: template.HTML(parsed.Html),
+ }
+ if err := ts.Execute(&tpl, data); err != nil {
+ continue
+ }
+ content = tpl.String()
+ case ".lxt":
+ parsed := shared.ListParseText(post.Text)
+ var tpl bytes.Buffer
+ data := &PostPageData{
+ List: parsed,
+ }
+ if err := ts.Execute(&tpl, data); err != nil {
+ continue
+ }
+ content = tpl.String()
- var tpl bytes.Buffer
- data := &PostPageData{
- Contents: template.HTML(parsed.Html),
- }
- if err := ts.Execute(&tpl, data); err != nil {
- continue
}
realUrl := cfg.FullPostURL(curl, post.Username, post.Slug)
@@ -810,7 +873,7 @@ func rssHandler(w http.ResponseWriter, r *http.Request) {
Id: realUrl,
Title: post.Title,
Link: &feeds.Link{Href: realUrl},
- Content: tpl.String(),
+ Content: content,
Created: *post.PublishAt,
Updated: *post.UpdatedAt,
Description: post.Description,
|