repos / pico

pico services - prose.sh, pastes.sh, imgs.sh, feeds.sh, pgs.sh
git clone https://github.com/picosh/pico.git

commit
9798290
parent
061bf1d
author
Eric Bower
date
2022-08-19 00:25:39 +0000 UTC
refactor: move prose markdown parser to shared
6 files changed,  +22, -23
M cmd/scripts/dates/dates.go
+2, -2
 1@@ -10,7 +10,7 @@ import (
 2 	"git.sr.ht/~erock/pico/db"
 3 	"git.sr.ht/~erock/pico/db/postgres"
 4 	"git.sr.ht/~erock/pico/lists"
 5-	"git.sr.ht/~erock/pico/prose"
 6+	"git.sr.ht/~erock/pico/shared"
 7 	"git.sr.ht/~erock/pico/wish/cms/config"
 8 	"go.uber.org/zap"
 9 )
10@@ -97,7 +97,7 @@ func main() {
11 	logger.Info("updating dates")
12 	for _, post := range posts {
13 		if post.Space == "prose" {
14-			parsed, err := prose.ParseText(post.Text)
15+			parsed, err := shared.ParseText(post.Text)
16 			if err != nil {
17 				logger.Error(err)
18 				continue
M cmd/scripts/tags/tags.go
+2, -2
 1@@ -7,7 +7,7 @@ import (
 2 
 3 	"git.sr.ht/~erock/pico/db"
 4 	"git.sr.ht/~erock/pico/db/postgres"
 5-	"git.sr.ht/~erock/pico/prose"
 6+	"git.sr.ht/~erock/pico/shared"
 7 	"git.sr.ht/~erock/pico/wish/cms/config"
 8 	"go.uber.org/zap"
 9 )
10@@ -75,7 +75,7 @@ func main() {
11 
12 	logger.Info("replacing tags")
13 	for _, post := range posts {
14-		parsed, err := prose.ParseText(post.Text)
15+		parsed, err := shared.ParseText(post.Text)
16 		if err != nil {
17 			continue
18 		}
M imgs/api.go
+2, -3
 1@@ -12,7 +12,6 @@ import (
 2 
 3 	"git.sr.ht/~erock/pico/db"
 4 	"git.sr.ht/~erock/pico/db/postgres"
 5-	"git.sr.ht/~erock/pico/prose"
 6 	"git.sr.ht/~erock/pico/shared"
 7 	"github.com/gorilla/feeds"
 8 	"golang.org/x/exp/slices"
 9@@ -489,7 +488,7 @@ func tagPostHandler(w http.ResponseWriter, r *http.Request) {
10 		return
11 	}
12 
13-	parsed, err := prose.ParseText(post.Text)
14+	parsed, err := shared.ParseText(post.Text)
15 	if err != nil {
16 		logger.Error(err)
17 	}
18@@ -572,7 +571,7 @@ func postHandler(w http.ResponseWriter, r *http.Request) {
19 	var data PostPageData
20 	post, err := dbpool.FindPostWithSlug(slug, user.ID, cfg.Space)
21 	if err == nil {
22-		parsed, err := prose.ParseText(post.Text)
23+		parsed, err := shared.ParseText(post.Text)
24 		if err != nil {
25 			logger.Error(err)
26 		}
M prose/api.go
+9, -14
 1@@ -80,15 +80,10 @@ type TransparencyPageData struct {
 2 	Analytics *db.Analytics
 3 }
 4 
 5-type Link struct {
 6-	URL  string
 7-	Text string
 8-}
 9-
10 type HeaderTxt struct {
11 	Title    string
12 	Bio      string
13-	Nav      []Link
14+	Nav      []shared.Link
15 	HasLinks bool
16 }
17 
18@@ -196,7 +191,7 @@ func blogHandler(w http.ResponseWriter, r *http.Request) {
19 		if post.Filename == "_styles.css" && len(post.Text) > 0 {
20 			hasCSS = true
21 		} else if post.Filename == "_readme.md" {
22-			parsedText, err := ParseText(post.Text)
23+			parsedText, err := shared.ParseText(post.Text)
24 			if err != nil {
25 				logger.Error(err)
26 			}
27@@ -205,7 +200,7 @@ func blogHandler(w http.ResponseWriter, r *http.Request) {
28 				headerTxt.Title = parsedText.Title
29 			}
30 
31-			headerTxt.Nav = []Link{}
32+			headerTxt.Nav = []shared.Link{}
33 			for _, nav := range parsedText.Nav {
34 				u, _ := url.Parse(nav.URL)
35 				finURL := nav.URL
36@@ -217,7 +212,7 @@ func blogHandler(w http.ResponseWriter, r *http.Request) {
37 						withUserName,
38 					)
39 				}
40-				headerTxt.Nav = append(headerTxt.Nav, Link{
41+				headerTxt.Nav = append(headerTxt.Nav, shared.Link{
42 					URL:  finURL,
43 					Text: nav.Text,
44 				})
45@@ -333,7 +328,7 @@ func postHandler(w http.ResponseWriter, r *http.Request) {
46 	var data PostPageData
47 	post, err := dbpool.FindPostWithSlug(slug, user.ID, cfg.Space)
48 	if err == nil {
49-		parsedText, err := ParseText(post.Text)
50+		parsedText, err := shared.ParseText(post.Text)
51 		if err != nil {
52 			logger.Error(err)
53 		}
54@@ -341,7 +336,7 @@ func postHandler(w http.ResponseWriter, r *http.Request) {
55 		// we need the blog name from the readme unfortunately
56 		readme, err := dbpool.FindPostWithFilename("_readme.md", user.ID, cfg.Space)
57 		if err == nil {
58-			readmeParsed, err := ParseText(readme.Text)
59+			readmeParsed, err := shared.ParseText(readme.Text)
60 			if err != nil {
61 				logger.Error(err)
62 			}
63@@ -547,7 +542,7 @@ func rssBlogHandler(w http.ResponseWriter, r *http.Request) {
64 
65 	for _, post := range posts {
66 		if post.Filename == "_readme.md" {
67-			parsedText, err := ParseText(post.Text)
68+			parsedText, err := shared.ParseText(post.Text)
69 			if err != nil {
70 				logger.Error(err)
71 			}
72@@ -582,7 +577,7 @@ func rssBlogHandler(w http.ResponseWriter, r *http.Request) {
73 		if slices.Contains(cfg.HiddenPosts, post.Filename) {
74 			continue
75 		}
76-		parsed, err := ParseText(post.Text)
77+		parsed, err := shared.ParseText(post.Text)
78 		if err != nil {
79 			logger.Error(err)
80 		}
81@@ -665,7 +660,7 @@ func rssHandler(w http.ResponseWriter, r *http.Request) {
82 
83 	var feedItems []*feeds.Item
84 	for _, post := range pager.Data {
85-		parsed, err := ParseText(post.Text)
86+		parsed, err := shared.ParseText(post.Text)
87 		if err != nil {
88 			logger.Error(err)
89 		}
M prose/scp_hooks.go
+1, -1
1@@ -45,7 +45,7 @@ func (p *MarkdownHooks) FileValidate(data *filehandlers.PostMetaData) (bool, err
2 }
3 
4 func (p *MarkdownHooks) FileMeta(data *filehandlers.PostMetaData) error {
5-	parsedText, err := ParseText(data.Text)
6+	parsedText, err := shared.ParseText(data.Text)
7 	// we return nil here because we don't want the file upload to fail
8 	if err != nil {
9 		return nil
R prose/parser.go => shared/mdparser.go
+6, -1
 1@@ -1,4 +1,4 @@
 2-package prose
 3+package shared
 4 
 5 import (
 6 	"bytes"
 7@@ -17,6 +17,11 @@ import (
 8 	ghtml "github.com/yuin/goldmark/renderer/html"
 9 )
10 
11+type Link struct {
12+	URL  string
13+	Text string
14+}
15+
16 type MetaData struct {
17 	PublishAt   *time.Time
18 	Title       string