repos / pico

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

commit
6509ea2
parent
d5828a4
author
Eric Bower
date
2022-08-02 17:19:45 +0000 UTC
fix: incorrect tag in yaml was breaking uploader and web render

Also added support for a string based tags value
2 files changed,  +23, -15
M prose/parser.go
+21, -14
 1@@ -80,6 +80,11 @@ func toTags(obj interface{}) ([]string, error) {
 2 		for _, tag := range raw {
 3 			arr = append(arr, tag.(string))
 4 		}
 5+	case string:
 6+		tags := strings.Split(raw, " ")
 7+		for _, tag := range tags {
 8+			arr = append(arr, strings.TrimSpace(tag))
 9+		}
10 	default:
11 		return arr, fmt.Errorf("unsupported type for `tags` variable: %T", raw)
12 	}
13@@ -90,6 +95,11 @@ func toTags(obj interface{}) ([]string, error) {
14 var reTimestamp = regexp.MustCompile(`T.+`)
15 
16 func ParseText(text string) (*ParsedText, error) {
17+	parsed := ParsedText{
18+		MetaData: &MetaData{
19+			Tags: []string{},
20+		},
21+	}
22 	var buf bytes.Buffer
23 	hili := highlighting.NewHighlighting(
24 		highlighting.WithFormatOptions(
25@@ -106,9 +116,12 @@ func ParseText(text string) (*ParsedText, error) {
26 	)
27 	context := parser.NewContext()
28 	if err := md.Convert([]byte(text), &buf, parser.WithContext(context)); err != nil {
29-		return &ParsedText{}, err
30+		return &parsed, err
31 	}
32+	parsed.Html = buf.String()
33 	metaData := meta.Get(context)
34+	parsed.MetaData.Title = toString(metaData["title"])
35+	parsed.MetaData.Description = toString(metaData["description"])
36 
37 	var publishAt *time.Time = nil
38 	var err error
39@@ -120,29 +133,23 @@ func ParseText(text string) (*ParsedText, error) {
40 
41 		nextDate, err := time.Parse("2006-01-02", date)
42 		if err != nil {
43-			return &ParsedText{}, err
44+			return &parsed, err
45 		}
46 		publishAt = &nextDate
47 	}
48+	parsed.MetaData.PublishAt = publishAt
49 
50 	nav, err := toLinks(metaData["nav"])
51 	if err != nil {
52-		return &ParsedText{}, err
53+		return &parsed, err
54 	}
55+	parsed.MetaData.Nav = nav
56 
57 	tags, err := toTags(metaData["tags"])
58 	if err != nil {
59-		return &ParsedText{}, err
60+		return &parsed, err
61 	}
62+	parsed.MetaData.Tags = tags
63 
64-	return &ParsedText{
65-		Html: buf.String(),
66-		MetaData: &MetaData{
67-			PublishAt:   publishAt,
68-			Title:       toString(metaData["title"]),
69-			Description: toString(metaData["description"]),
70-			Nav:         nav,
71-			Tags:        tags,
72-		},
73-	}, nil
74+	return &parsed, nil
75 }
M prose/scp_hooks.go
+2, -1
 1@@ -44,8 +44,9 @@ func (p *MarkdownHooks) FileValidate(text string, filename string) (bool, error)
 2 
 3 func (p *MarkdownHooks) FileMeta(text string, data *filehandlers.PostMetaData) error {
 4 	parsedText, err := ParseText(text)
 5+	// we return nil here because we don't want the file upload to fail
 6 	if err != nil {
 7-		return err
 8+		return nil
 9 	}
10 
11 	if parsedText.Title != "" {