diff --git a/cmd/owl/web/editor_handler.go b/cmd/owl/web/editor_handler.go index fa34ba3..ce449c6 100644 --- a/cmd/owl/web/editor_handler.go +++ b/cmd/owl/web/editor_handler.go @@ -201,15 +201,38 @@ func userEditorPostHandler(repo *owl.Repository) func(http.ResponseWriter, *http content := r.Form.Get("content") draft := r.Form.Get("draft") + // conditional values + reply_url := r.Form.Get("reply_url") + bookmark_url := r.Form.Get("bookmark_url") + // validate form values - if post_type == "article" && title == "" { - userEditorGetHandler(repo)(w, r, ps) - return - } if post_type == "" { userEditorGetHandler(repo)(w, r, ps) return } + if post_type == "article" && title == "" { + userEditorGetHandler(repo)(w, r, ps) + return + } + if post_type == "reply" && reply_url == "" { + html, _ := owl.RenderUserError(user, owl.ErrorMessage{ + Error: "Missing URL", + Message: "You must provide a URL to reply to", + }) + w.Write([]byte(html)) + return + } + if post_type == "bookmark" && bookmark_url == "" { + html, _ := owl.RenderUserError(user, owl.ErrorMessage{ + Error: "Missing URL", + Message: "You must provide a URL to bookmark", + }) + w.Write([]byte(html)) + return + } + + // TODO: scrape reply_url for title and description + // TODO: scrape bookmark_url for title and description // create post post, err := user.CreateNewPostFull(owl.PostMeta{ @@ -218,6 +241,12 @@ func userEditorPostHandler(repo *owl.Repository) func(http.ResponseWriter, *http Description: description, Draft: draft == "on", Date: time.Now(), + Reply: owl.Reply{ + Url: reply_url, + }, + Bookmark: owl.Bookmark{ + Url: bookmark_url, + }, }, content) if err != nil { diff --git a/embed/editor/editor.html b/embed/editor/editor.html index 5924540..b93f50d 100644 --- a/embed/editor/editor.html +++ b/embed/editor/editor.html @@ -28,4 +28,46 @@

+ + +
+ Write Reply +
+

Create New Reply

+ + + + + + + + + + + + +

+ +
+
+ +
+ Bookmark +
+

Create Bookmark

+ + + + + + + + + + + + +

+ +
\ No newline at end of file diff --git a/embed/post.html b/embed/post.html index 35cfd95..b08301d 100644 --- a/embed/post.html +++ b/embed/post.html @@ -33,6 +33,18 @@

{{ end }} + {{ if .Post.Meta.Bookmark.Url }} +

+ Bookmark: + {{ if .Post.Meta.Bookmark.Text }} + {{.Post.Meta.Bookmark.Text}} + {{ else }} + {{.Post.Meta.Bookmark.Url}} + {{ end }} + +

+ {{ end }} +
{{.Content}}
diff --git a/post.go b/post.go index 08961c0..90eb5cf 100644 --- a/post.go +++ b/post.go @@ -30,6 +30,10 @@ type Reply struct { Url string `yaml:"url"` Text string `yaml:"text"` } +type Bookmark struct { + Url string `yaml:"url"` + Text string `yaml:"text"` +} type PostMeta struct { Type string `yaml:"type"` @@ -39,6 +43,7 @@ type PostMeta struct { Date time.Time `yaml:"date"` Draft bool `yaml:"draft"` Reply Reply `yaml:"reply"` + Bookmark Bookmark `yaml:"bookmark"` } func (pm PostMeta) FormattedDate() string { @@ -53,6 +58,7 @@ func (pm *PostMeta) UnmarshalYAML(unmarshal func(interface{}) error) error { Aliases []string `yaml:"aliases"` Draft bool `yaml:"draft"` Reply Reply `yaml:"reply"` + Bookmark Bookmark `yaml:"bookmark"` } type S struct { Date string `yaml:"date"` @@ -76,6 +82,7 @@ func (pm *PostMeta) UnmarshalYAML(unmarshal func(interface{}) error) error { pm.Aliases = t.Aliases pm.Draft = t.Draft pm.Reply = t.Reply + pm.Bookmark = t.Bookmark possibleFormats := []string{ "2006-01-02", diff --git a/renderer_test.go b/renderer_test.go index 62bbe13..299a6ef 100644 --- a/renderer_test.go +++ b/renderer_test.go @@ -338,6 +338,14 @@ func TestRenderReplyWithText(t *testing.T) { assertions.AssertContains(t, result, "This is a reply") } +func TestRengerPostContainsBookmark(t *testing.T) { + user := getTestUser() + post, _ := user.CreateNewPostFull(owl.PostMeta{Type: "bookmark", Bookmark: owl.Bookmark{Url: "https://example.com/post"}}, "hi") + + result, _ := owl.RenderPost(post) + assertions.AssertContains(t, result, "https://example.com/post") +} + func TestOpenGraphTags(t *testing.T) { user := getTestUser() post, _ := user.CreateNewPost("testpost", false)