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
|
diff --git a/pkg/apps/prose/api.go b/pkg/apps/prose/api.go
index d9ab861..7a807aa 100644
--- a/pkg/apps/prose/api.go
+++ b/pkg/apps/prose/api.go
@@ -41,18 +41,17 @@ type PostItemData struct {
}
type BlogPageData struct {
- Site shared.SitePageData
- PageTitle string
- URL template.URL
- RSSURL template.URL
- Username string
- Readme *ReadmeTxt
- Header *HeaderTxt
- Posts []PostItemData
- HasCSS bool
- WithStyles bool
- CssURL template.URL
- HasFilter bool
+ Site shared.SitePageData
+ PageTitle string
+ URL template.URL
+ RSSURL template.URL
+ Username string
+ Readme *ReadmeTxt
+ Header *HeaderTxt
+ Posts []PostItemData
+ HasCSS bool
+ CssURL template.URL
+ HasFilter bool
}
type ReadPageData struct {
@@ -78,7 +77,6 @@ type PostPageData struct {
PublishAtISO string
PublishAt string
HasCSS bool
- WithStyles bool
CssURL template.URL
Tags []string
Image template.URL
@@ -90,16 +88,15 @@ type PostPageData struct {
}
type HeaderTxt struct {
- Title string
- Bio string
- Nav []shared.Link
- HasLinks bool
- Layout string
- Image template.URL
- ImageCard string
- Favicon template.URL
- WithStyles bool
- Domain string
+ Title string
+ Bio string
+ Nav []shared.Link
+ HasLinks bool
+ Layout string
+ Image template.URL
+ ImageCard string
+ Favicon template.URL
+ Domain string
}
type ReadmeTxt struct {
@@ -134,15 +131,27 @@ func blogStyleHandler(w http.ResponseWriter, r *http.Request) {
logger = shared.LoggerWithUser(logger, user)
styles, err := dbpool.FindPostWithFilename("_styles.css", user.ID, cfg.Space)
- if err != nil {
- logger.Info("css not found")
- http.Error(w, "css not found", http.StatusNotFound)
- return
+ var txt []byte
+ if err == nil {
+ txt = []byte(styles.Text)
+ logger.Info("custom css found")
+ } else {
+ fp := cfg.StaticPath(fmt.Sprintf("public/%s", "smol.css"))
+ if user.CreatedAt.After(time.Date(2025, 5, 3, 0, 0, 0, 0, time.Local)) {
+ fp = cfg.StaticPath(fmt.Sprintf("public/%s", "smol-v2.css"))
+ }
+ txt, err = os.ReadFile(fp)
+ if err != nil {
+ logger.Error("read default css file", "err", err)
+ http.Error(w, "default css file not found", http.StatusInternalServerError)
+ return
+ }
+ logger.Info("custom css not found, loading default")
}
w.Header().Add("Content-Type", "text/css")
- _, err = w.Write([]byte(styles.Text))
+ _, err = w.Write(txt)
if err != nil {
logger.Error("write to response writer", "err", err.Error())
http.Error(w, "server error", 500)
@@ -195,11 +204,10 @@ func blogHandler(w http.ResponseWriter, r *http.Request) {
}
headerTxt := &HeaderTxt{
- Title: GetBlogName(username),
- Bio: "",
- Layout: "default",
- ImageCard: "summary",
- WithStyles: true,
+ Title: GetBlogName(username),
+ Bio: "",
+ Layout: "default",
+ ImageCard: "summary",
}
readmeTxt := &ReadmeTxt{}
@@ -213,7 +221,6 @@ func blogHandler(w http.ResponseWriter, r *http.Request) {
headerTxt.Layout = parsedText.Layout
headerTxt.Image = template.URL(parsedText.Image)
headerTxt.ImageCard = parsedText.ImageCard
- headerTxt.WithStyles = parsedText.WithStyles
headerTxt.Favicon = template.URL(parsedText.Favicon)
if parsedText.Title != "" {
headerTxt.Title = parsedText.Title
@@ -263,18 +270,17 @@ func blogHandler(w http.ResponseWriter, r *http.Request) {
}
data := BlogPageData{
- Site: *cfg.GetSiteData(),
- PageTitle: headerTxt.Title,
- URL: template.URL(cfg.FullBlogURL(curl, username)),
- RSSURL: template.URL(cfg.RssBlogURL(curl, username, tag)),
- Readme: readmeTxt,
- Header: headerTxt,
- Username: username,
- Posts: postCollection,
- HasCSS: hasCSS,
- CssURL: template.URL(cfg.CssURL(username)),
- HasFilter: tag != "",
- WithStyles: headerTxt.WithStyles,
+ Site: *cfg.GetSiteData(),
+ PageTitle: headerTxt.Title,
+ URL: template.URL(cfg.FullBlogURL(curl, username)),
+ RSSURL: template.URL(cfg.RssBlogURL(curl, username, tag)),
+ Readme: readmeTxt,
+ Header: headerTxt,
+ Username: username,
+ Posts: postCollection,
+ HasCSS: hasCSS,
+ CssURL: template.URL(cfg.CssURL(username)),
+ HasFilter: tag != "",
}
err = ts.Execute(w, data)
@@ -357,17 +363,8 @@ func postHandler(w http.ResponseWriter, r *http.Request) {
favicon := ""
ogImage := ""
ogImageCard := ""
- hasCSS := false
- withStyles := true
var data PostPageData
- css, err := dbpool.FindPostWithFilename("_styles.css", user.ID, cfg.Space)
- if err == nil {
- if len(css.Text) > 0 {
- hasCSS = true
- }
- }
-
footer, err := dbpool.FindPostWithFilename("_footer.md", user.ID, cfg.Space)
var footerHTML template.HTML
if err == nil {
@@ -388,7 +385,6 @@ func postHandler(w http.ResponseWriter, r *http.Request) {
if readmeParsed.MetaData.Title != "" {
blogName = readmeParsed.MetaData.Title
}
- withStyles = readmeParsed.WithStyles
ogImage = readmeParsed.Image
ogImageCard = readmeParsed.ImageCard
favicon = readmeParsed.Favicon
@@ -429,7 +425,6 @@ func postHandler(w http.ResponseWriter, r *http.Request) {
Username: username,
BlogName: blogName,
Contents: template.HTML(parsedText.Html),
- HasCSS: hasCSS,
CssURL: template.URL(cfg.CssURL(username)),
Tags: parsedText.Tags,
Image: template.URL(ogImage),
@@ -438,7 +433,6 @@ func postHandler(w http.ResponseWriter, r *http.Request) {
Footer: footerHTML,
Unlisted: unlisted,
Diff: template.HTML(diff),
- WithStyles: withStyles,
}
} else {
logger.Info("post not found")
@@ -473,7 +467,6 @@ func postHandler(w http.ResponseWriter, r *http.Request) {
PublishAtISO: time.Now().Format(time.RFC3339),
Username: username,
BlogName: blogName,
- HasCSS: hasCSS,
CssURL: template.URL(cfg.CssURL(username)),
Image: template.URL(ogImage),
ImageCard: ogImageCard,
@@ -481,7 +474,6 @@ func postHandler(w http.ResponseWriter, r *http.Request) {
Footer: footerHTML,
Contents: contents,
Unlisted: true,
- WithStyles: withStyles,
}
w.WriteHeader(http.StatusNotFound)
}
|