pico

created pr with 67.1 on 2025-05-03T17:32:51Z · by c8ef7d19
cmds
checkout latest patchset:
ssh pr.pico.sh print 67 | git am -3
checkout any patchset in a patch request:
ssh pr.pico.sh print 67.[rev] | git am -3
add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh pr add 67

Patchset 67.1 on 2025-05-03T17:32:51Z · commit 2f50c9a

refactor(prose): unified _styles.css handler
Eric Bower 2025-05-03T17:31:22Z
BREAKING CHANGE: `with_styles` is deprecated and users cannot "tweak"
the default stylesheet, they will have to copy and then upload it with
tweaks.
Semantic diff summary
0 added, 6 modified, 0 signature changed, 0 removed across 1 analyzed file (2 files skipped: unsupported file type)
+52 -60 pkg/apps/prose/api.go #
......@@ -41,18 +41,17 @@ type PostItemData struct {
4141 }
4242
4343 type BlogPageData struct {
44- Site shared.SitePageData
45- PageTitle string
46- URL template.URL
47- RSSURL template.URL
48- Username string
49- Readme *ReadmeTxt
50- Header *HeaderTxt
51- Posts []PostItemData
52- HasCSS bool
53- WithStyles bool
54- CssURL template.URL
55- HasFilter bool
44+ Site shared.SitePageData
45+ PageTitle string
46+ URL template.URL
47+ RSSURL template.URL
48+ Username string
49+ Readme *ReadmeTxt
50+ Header *HeaderTxt
51+ Posts []PostItemData
52+ HasCSS bool
53+ CssURL template.URL
54+ HasFilter bool
5655 }
5756
5857 type ReadPageData struct {
......@@ -78,7 +77,6 @@ type PostPageData struct {
7877 PublishAtISO string
7978 PublishAt string
8079 HasCSS bool
81- WithStyles bool
8280 CssURL template.URL
8381 Tags []string
8482 Image template.URL
......@@ -90,16 +88,15 @@ type PostPageData struct {
9088 }
9189
9290 type HeaderTxt struct {
93- Title string
94- Bio string
95- Nav []shared.Link
96- HasLinks bool
97- Layout string
98- Image template.URL
99- ImageCard string
100- Favicon template.URL
101- WithStyles bool
102- Domain string
91+ Title string
92+ Bio string
93+ Nav []shared.Link
94+ HasLinks bool
95+ Layout string
96+ Image template.URL
97+ ImageCard string
98+ Favicon template.URL
99+ Domain string
103100 }
104101
105102 type ReadmeTxt struct {
......@@ -134,15 +131,27 @@ func blogStyleHandler(w http.ResponseWriter, r *http.Request) {
134131 logger = shared.LoggerWithUser(logger, user)
135132
136133 styles, err := dbpool.FindPostWithFilename("_styles.css", user.ID, cfg.Space)
137- if err != nil {
138- logger.Info("css not found")
139- http.Error(w, "css not found", http.StatusNotFound)
140- return
134+ var txt []byte
135+ if err == nil {
136+ txt = []byte(styles.Text)
137+ logger.Info("custom css found")
138+ } else {
139+ fp := cfg.StaticPath(fmt.Sprintf("public/%s", "smol.css"))
140+ if user.CreatedAt.After(time.Date(2025, 5, 3, 0, 0, 0, 0, time.Local)) {
141+ fp = cfg.StaticPath(fmt.Sprintf("public/%s", "smol-v2.css"))
142+ }
143+ txt, err = os.ReadFile(fp)
144+ if err != nil {
145+ logger.Error("read default css file", "err", err)
146+ http.Error(w, "default css file not found", http.StatusInternalServerError)
147+ return
148+ }
149+ logger.Info("custom css not found, loading default")
141150 }
142151
143152 w.Header().Add("Content-Type", "text/css")
144153
145- _, err = w.Write([]byte(styles.Text))
154+ _, err = w.Write(txt)
146155 if err != nil {
147156 logger.Error("write to response writer", "err", err.Error())
148157 http.Error(w, "server error", 500)
......@@ -195,11 +204,10 @@ func blogHandler(w http.ResponseWriter, r *http.Request) {
195204 }
196205
197206 headerTxt := &HeaderTxt{
198- Title: GetBlogName(username),
199- Bio: "",
200- Layout: "default",
201- ImageCard: "summary",
202- WithStyles: true,
207+ Title: GetBlogName(username),
208+ Bio: "",
209+ Layout: "default",
210+ ImageCard: "summary",
203211 }
204212 readmeTxt := &ReadmeTxt{}
205213
......@@ -213,7 +221,6 @@ func blogHandler(w http.ResponseWriter, r *http.Request) {
213221 headerTxt.Layout = parsedText.Layout
214222 headerTxt.Image = template.URL(parsedText.Image)
215223 headerTxt.ImageCard = parsedText.ImageCard
216- headerTxt.WithStyles = parsedText.WithStyles
217224 headerTxt.Favicon = template.URL(parsedText.Favicon)
218225 if parsedText.Title != "" {
219226 headerTxt.Title = parsedText.Title
......@@ -263,18 +270,17 @@ func blogHandler(w http.ResponseWriter, r *http.Request) {
263270 }
264271
265272 data := BlogPageData{
266- Site: *cfg.GetSiteData(),
267- PageTitle: headerTxt.Title,
268- URL: template.URL(cfg.FullBlogURL(curl, username)),
269- RSSURL: template.URL(cfg.RssBlogURL(curl, username, tag)),
270- Readme: readmeTxt,
271- Header: headerTxt,
272- Username: username,
273- Posts: postCollection,
274- HasCSS: hasCSS,
275- CssURL: template.URL(cfg.CssURL(username)),
276- HasFilter: tag != "",
277- WithStyles: headerTxt.WithStyles,
273+ Site: *cfg.GetSiteData(),
274+ PageTitle: headerTxt.Title,
275+ URL: template.URL(cfg.FullBlogURL(curl, username)),
276+ RSSURL: template.URL(cfg.RssBlogURL(curl, username, tag)),
277+ Readme: readmeTxt,
278+ Header: headerTxt,
279+ Username: username,
280+ Posts: postCollection,
281+ HasCSS: hasCSS,
282+ CssURL: template.URL(cfg.CssURL(username)),
283+ HasFilter: tag != "",
278284 }
279285
280286 err = ts.Execute(w, data)
......@@ -357,17 +363,8 @@ func postHandler(w http.ResponseWriter, r *http.Request) {
357363 favicon := ""
358364 ogImage := ""
359365 ogImageCard := ""
360- hasCSS := false
361- withStyles := true
362366 var data PostPageData
363367
364- css, err := dbpool.FindPostWithFilename("_styles.css", user.ID, cfg.Space)
365- if err == nil {
366- if len(css.Text) > 0 {
367- hasCSS = true
368- }
369- }
370-
371368 footer, err := dbpool.FindPostWithFilename("_footer.md", user.ID, cfg.Space)
372369 var footerHTML template.HTML
373370 if err == nil {
......@@ -388,7 +385,6 @@ func postHandler(w http.ResponseWriter, r *http.Request) {
388385 if readmeParsed.MetaData.Title != "" {
389386 blogName = readmeParsed.MetaData.Title
390387 }
391- withStyles = readmeParsed.WithStyles
392388 ogImage = readmeParsed.Image
393389 ogImageCard = readmeParsed.ImageCard
394390 favicon = readmeParsed.Favicon
......@@ -429,7 +425,6 @@ func postHandler(w http.ResponseWriter, r *http.Request) {
429425 Username: username,
430426 BlogName: blogName,
431427 Contents: template.HTML(parsedText.Html),
432- HasCSS: hasCSS,
433428 CssURL: template.URL(cfg.CssURL(username)),
434429 Tags: parsedText.Tags,
435430 Image: template.URL(ogImage),
......@@ -438,7 +433,6 @@ func postHandler(w http.ResponseWriter, r *http.Request) {
438433 Footer: footerHTML,
439434 Unlisted: unlisted,
440435 Diff: template.HTML(diff),
441- WithStyles: withStyles,
442436 }
443437 } else {
444438 logger.Info("post not found")
......@@ -473,7 +467,6 @@ func postHandler(w http.ResponseWriter, r *http.Request) {
473467 PublishAtISO: time.Now().Format(time.RFC3339),
474468 Username: username,
475469 BlogName: blogName,
476- HasCSS: hasCSS,
477470 CssURL: template.URL(cfg.CssURL(username)),
478471 Image: template.URL(ogImage),
479472 ImageCard: ogImageCard,
......@@ -481,7 +474,6 @@ func postHandler(w http.ResponseWriter, r *http.Request) {
481474 Footer: footerHTML,
482475 Contents: contents,
483476 Unlisted: true,
484- WithStyles: withStyles,
485477 }
486478 w.WriteHeader(http.StatusNotFound)
487479 }
+1 -5 pkg/apps/prose/html/blog.page.tmpl #
......@@ -41,12 +41,8 @@
4141 {{if .Header.Bio}}<meta property="twitter:description" content="{{.Header.Bio}}">{{end}}
4242
4343 <link rel="alternate" href="{{.RSSURL}}" type="application/rss+xml" title="RSS feed for {{.Header.Title}}" />
44-{{if .WithStyles}}
45- <link rel="stylesheet" href="/smol.css" />
46-{{else}}
47-{{end}}
4844 <link rel="stylesheet" href="/syntax.css" />
49-{{if .HasCSS}}<link rel="stylesheet" href="{{.CssURL}}" />{{end}}
45+<link rel="stylesheet" href="{{.CssURL}}" />
5046 {{end}}
5147
5248 {{define "attrs"}}id="blog" class="layout-{{.Header.Layout}}"{{end}}
+1 -5 pkg/apps/prose/html/post.page.tmpl #
......@@ -41,11 +41,7 @@
4141 {{if .Description}}<meta property="twitter:description" content="{{.Description}}">{{end}}
4242
4343 <link rel="stylesheet" href="/syntax.css" />
44-{{if .WithStyles}}
45- <link rel="stylesheet" href="/smol.css" />
46-{{else}}
47-{{end}}
48-{{if .HasCSS}}<link rel="stylesheet" href="{{.CssURL}}" />{{end}}
44+<link rel="stylesheet" href="{{.CssURL}}" />
4945 {{end}}
5046
5147 {{define "attrs"}}id="post" class="{{.Slug}}"{{end}}
Back to top