bookmark and reply in editor
This commit is contained in:
parent
0d5e6599cf
commit
65fa4f6fb8
|
@ -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 {
|
||||
|
|
|
@ -29,3 +29,45 @@
|
|||
<input type="submit" value="Create Note" />
|
||||
</form>
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>Write Reply</summary>
|
||||
<form action="" method="post">
|
||||
<h2>Create New Reply</h2>
|
||||
<input type="hidden" name="csrf_token" value="{{.CsrfToken}}">
|
||||
<input type="hidden" name="type" value="reply">
|
||||
|
||||
<label for="reply_url">Reply To</label>
|
||||
<input type="text" name="reply_url" placeholder="URL" />
|
||||
|
||||
<label for="title">Title</label>
|
||||
<input type="text" name="title" placeholder="Title" />
|
||||
|
||||
<label for="content">Content</label>
|
||||
<textarea name="content" placeholder="Content" rows="8"></textarea>
|
||||
|
||||
<br><br>
|
||||
<input type="submit" value="Create Reply" />
|
||||
</form>
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>Bookmark</summary>
|
||||
<form action="" method="post">
|
||||
<h2>Create Bookmark</h2>
|
||||
<input type="hidden" name="csrf_token" value="{{.CsrfToken}}">
|
||||
<input type="hidden" name="type" value="bookmark">
|
||||
|
||||
<label for="bookmark_url">Bookmark</label>
|
||||
<input type="text" name="bookmark_url" placeholder="URL" />
|
||||
|
||||
<label for="title">Title</label>
|
||||
<input type="text" name="title" placeholder="Title" />
|
||||
|
||||
<label for="content">Content</label>
|
||||
<textarea name="content" placeholder="Content" rows="8"></textarea>
|
||||
|
||||
<br><br>
|
||||
<input type="submit" value="Create Bookmark" />
|
||||
</form>
|
||||
</details>
|
|
@ -33,6 +33,18 @@
|
|||
</p>
|
||||
{{ end }}
|
||||
|
||||
{{ if .Post.Meta.Bookmark.Url }}
|
||||
<p style="font-style: italic;filter: opacity(80%);">
|
||||
Bookmark: <a class="u-bookmark-of h-cite" href="{{.Post.Meta.Bookmark.Url}}">
|
||||
{{ if .Post.Meta.Bookmark.Text }}
|
||||
{{.Post.Meta.Bookmark.Text}}
|
||||
{{ else }}
|
||||
{{.Post.Meta.Bookmark.Url}}
|
||||
{{ end }}
|
||||
</a>
|
||||
</p>
|
||||
{{ end }}
|
||||
|
||||
<div class="e-content">
|
||||
{{.Content}}
|
||||
</div>
|
||||
|
|
7
post.go
7
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",
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue