more types
This commit is contained in:
parent
b61e2ff50c
commit
1fefa2a140
|
@ -251,10 +251,10 @@ func userEditorPostHandler(repo *owl.Repository) func(http.ResponseWriter, *http
|
||||||
Description: description,
|
Description: description,
|
||||||
Draft: draft == "on",
|
Draft: draft == "on",
|
||||||
Date: time.Now(),
|
Date: time.Now(),
|
||||||
Reply: owl.Reply{
|
Reply: owl.ReplyData{
|
||||||
Url: reply_url,
|
Url: reply_url,
|
||||||
},
|
},
|
||||||
Bookmark: owl.Bookmark{
|
Bookmark: owl.BookmarkData{
|
||||||
Url: bookmark_url,
|
Url: bookmark_url,
|
||||||
},
|
},
|
||||||
}, content)
|
}, content)
|
||||||
|
|
|
@ -336,7 +336,7 @@ func userMicropubHandler(repo *owl.Repository) func(http.ResponseWriter, *http.R
|
||||||
post, err := user.CreateNewPostFull(
|
post, err := user.CreateNewPostFull(
|
||||||
owl.PostMeta{
|
owl.PostMeta{
|
||||||
Title: name,
|
Title: name,
|
||||||
Reply: owl.Reply{
|
Reply: owl.ReplyData{
|
||||||
Url: inReplyTo,
|
Url: inReplyTo,
|
||||||
},
|
},
|
||||||
Date: time.Now(),
|
Date: time.Now(),
|
||||||
|
|
|
@ -22,18 +22,6 @@
|
||||||
<hr>
|
<hr>
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
{{ if .Post.Meta.Reply.Url }}
|
|
||||||
<p style="font-style: italic;filter: opacity(80%);">
|
|
||||||
In reply to: <a class="u-in-reply-to h-cite" rel="in-reply-to" href="{{.Post.Meta.Reply.Url}}">
|
|
||||||
{{ if .Post.Meta.Reply.Text }}
|
|
||||||
{{.Post.Meta.Reply.Text}}
|
|
||||||
{{ else }}
|
|
||||||
{{.Post.Meta.Reply.Url}}
|
|
||||||
{{ end }}
|
|
||||||
</a>
|
|
||||||
</p>
|
|
||||||
{{ end }}
|
|
||||||
|
|
||||||
{{ if .Post.Meta.Bookmark.Url }}
|
{{ if .Post.Meta.Bookmark.Url }}
|
||||||
<p style="font-style: italic;filter: opacity(80%);">
|
<p style="font-style: italic;filter: opacity(80%);">
|
||||||
Bookmark: <a class="u-bookmark-of h-cite" href="{{.Post.Meta.Bookmark.Url}}">
|
Bookmark: <a class="u-bookmark-of h-cite" href="{{.Post.Meta.Bookmark.Url}}">
|
||||||
|
|
|
@ -0,0 +1,72 @@
|
||||||
|
<div class="h-entry">
|
||||||
|
<hgroup>
|
||||||
|
<h1 class="p-name">{{.Title}}</h1>
|
||||||
|
<small>
|
||||||
|
<a class="u-url" href="{{.Post.FullUrl}}">#</a>
|
||||||
|
Published:
|
||||||
|
<time class="dt-published" datetime="{{.Post.Meta.Date}}">
|
||||||
|
{{.Post.Meta.FormattedDate}}
|
||||||
|
</time>
|
||||||
|
{{ if .Post.User.Config.AuthorName }}
|
||||||
|
by
|
||||||
|
<a class="p-author h-card" href="{{.Post.User.FullUrl}}">
|
||||||
|
{{ if .Post.User.AvatarUrl }}
|
||||||
|
<img class="u-photo u-logo" style="height: 1em;" src="{{ .Post.User.AvatarUrl }}"
|
||||||
|
alt="{{ .Post.User.Config.Title }}" />
|
||||||
|
{{ end }}
|
||||||
|
{{.Post.User.Config.AuthorName}}
|
||||||
|
</a>
|
||||||
|
{{ end }}
|
||||||
|
</small>
|
||||||
|
</hgroup>
|
||||||
|
<hr>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
{{ if .Post.Meta.Reply.Url }}
|
||||||
|
<p style="font-style: italic;filter: opacity(80%);">
|
||||||
|
In reply to: <a class="u-in-reply-to h-cite" rel="in-reply-to" href="{{.Post.Meta.Reply.Url}}">
|
||||||
|
{{ if .Post.Meta.Reply.Text }}
|
||||||
|
{{.Post.Meta.Reply.Text}}
|
||||||
|
{{ else }}
|
||||||
|
{{.Post.Meta.Reply.Url}}
|
||||||
|
{{ end }}
|
||||||
|
</a>
|
||||||
|
</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>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
{{if .Post.ApprovedIncomingWebmentions}}
|
||||||
|
<h3>
|
||||||
|
Webmentions
|
||||||
|
</h3>
|
||||||
|
<ul>
|
||||||
|
{{range .Post.ApprovedIncomingWebmentions}}
|
||||||
|
<li>
|
||||||
|
<a href="{{.Source}}">
|
||||||
|
{{if .Title}}
|
||||||
|
{{.Title}}
|
||||||
|
{{else}}
|
||||||
|
{{.Source}}
|
||||||
|
{{end}}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{end}}
|
||||||
|
</ul>
|
||||||
|
{{end}}
|
||||||
|
</div>
|
|
@ -1,6 +1,5 @@
|
||||||
<div class="h-entry">
|
<div class="h-entry">
|
||||||
<hgroup>
|
<hgroup>
|
||||||
<h1 class="p-name">{{.Title}}</h1>
|
|
||||||
<small>
|
<small>
|
||||||
<a class="u-url" href="{{.Post.FullUrl}}">#</a>
|
<a class="u-url" href="{{.Post.FullUrl}}">#</a>
|
||||||
Published:
|
Published:
|
||||||
|
@ -22,30 +21,6 @@
|
||||||
<hr>
|
<hr>
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
{{ if .Post.Meta.Reply.Url }}
|
|
||||||
<p style="font-style: italic;filter: opacity(80%);">
|
|
||||||
In reply to: <a class="u-in-reply-to h-cite" rel="in-reply-to" href="{{.Post.Meta.Reply.Url}}">
|
|
||||||
{{ if .Post.Meta.Reply.Text }}
|
|
||||||
{{.Post.Meta.Reply.Text}}
|
|
||||||
{{ else }}
|
|
||||||
{{.Post.Meta.Reply.Url}}
|
|
||||||
{{ end }}
|
|
||||||
</a>
|
|
||||||
</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">
|
<div class="e-content">
|
||||||
{{.Content}}
|
{{.Content}}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
<div class="h-entry">
|
||||||
|
<hgroup>
|
||||||
|
<h1 class="p-name">{{.Title}}</h1>
|
||||||
|
<small>
|
||||||
|
<a class="u-url" href="{{.Post.FullUrl}}">#</a>
|
||||||
|
Published:
|
||||||
|
<time class="dt-published" datetime="{{.Post.Meta.Date}}">
|
||||||
|
{{.Post.Meta.FormattedDate}}
|
||||||
|
</time>
|
||||||
|
{{ if .Post.User.Config.AuthorName }}
|
||||||
|
by
|
||||||
|
<a class="p-author h-card" href="{{.Post.User.FullUrl}}">
|
||||||
|
{{ if .Post.User.AvatarUrl }}
|
||||||
|
<img class="u-photo u-logo" style="height: 1em;" src="{{ .Post.User.AvatarUrl }}"
|
||||||
|
alt="{{ .Post.User.Config.Title }}" />
|
||||||
|
{{ end }}
|
||||||
|
{{.Post.User.Config.AuthorName}}
|
||||||
|
</a>
|
||||||
|
{{ end }}
|
||||||
|
</small>
|
||||||
|
</hgroup>
|
||||||
|
<hr>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
{{ if .Post.Meta.Reply.Url }}
|
||||||
|
<p style="font-style: italic;filter: opacity(80%);">
|
||||||
|
In reply to: <a class="u-in-reply-to h-cite" rel="in-reply-to" href="{{.Post.Meta.Reply.Url}}">
|
||||||
|
{{ if .Post.Meta.Reply.Text }}
|
||||||
|
{{.Post.Meta.Reply.Text}}
|
||||||
|
{{ else }}
|
||||||
|
{{.Post.Meta.Reply.Url}}
|
||||||
|
{{ end }}
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
|
<div class="e-content">
|
||||||
|
{{.Content}}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
{{if .Post.ApprovedIncomingWebmentions}}
|
||||||
|
<h3>
|
||||||
|
Webmentions
|
||||||
|
</h3>
|
||||||
|
<ul>
|
||||||
|
{{range .Post.ApprovedIncomingWebmentions}}
|
||||||
|
<li>
|
||||||
|
<a href="{{.Source}}">
|
||||||
|
{{if .Title}}
|
||||||
|
{{.Title}}
|
||||||
|
{{else}}
|
||||||
|
{{.Source}}
|
||||||
|
{{end}}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{end}}
|
||||||
|
</ul>
|
||||||
|
{{end}}
|
||||||
|
</div>
|
|
@ -0,0 +1,72 @@
|
||||||
|
<div class="h-entry">
|
||||||
|
<hgroup>
|
||||||
|
<h1 class="p-name">{{.Title}}</h1>
|
||||||
|
<small>
|
||||||
|
<a class="u-url" href="{{.Post.FullUrl}}">#</a>
|
||||||
|
Published:
|
||||||
|
<time class="dt-published" datetime="{{.Post.Meta.Date}}">
|
||||||
|
{{.Post.Meta.FormattedDate}}
|
||||||
|
</time>
|
||||||
|
{{ if .Post.User.Config.AuthorName }}
|
||||||
|
by
|
||||||
|
<a class="p-author h-card" href="{{.Post.User.FullUrl}}">
|
||||||
|
{{ if .Post.User.AvatarUrl }}
|
||||||
|
<img class="u-photo u-logo" style="height: 1em;" src="{{ .Post.User.AvatarUrl }}"
|
||||||
|
alt="{{ .Post.User.Config.Title }}" />
|
||||||
|
{{ end }}
|
||||||
|
{{.Post.User.Config.AuthorName}}
|
||||||
|
</a>
|
||||||
|
{{ end }}
|
||||||
|
</small>
|
||||||
|
</hgroup>
|
||||||
|
<hr>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
{{ if .Post.Meta.Reply.Url }}
|
||||||
|
<p style="font-style: italic;filter: opacity(80%);">
|
||||||
|
In reply to: <a class="u-in-reply-to h-cite" rel="in-reply-to" href="{{.Post.Meta.Reply.Url}}">
|
||||||
|
{{ if .Post.Meta.Reply.Text }}
|
||||||
|
{{.Post.Meta.Reply.Text}}
|
||||||
|
{{ else }}
|
||||||
|
{{.Post.Meta.Reply.Url}}
|
||||||
|
{{ end }}
|
||||||
|
</a>
|
||||||
|
</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>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
{{if .Post.ApprovedIncomingWebmentions}}
|
||||||
|
<h3>
|
||||||
|
Webmentions
|
||||||
|
</h3>
|
||||||
|
<ul>
|
||||||
|
{{range .Post.ApprovedIncomingWebmentions}}
|
||||||
|
<li>
|
||||||
|
<a href="{{.Source}}">
|
||||||
|
{{if .Title}}
|
||||||
|
{{.Title}}
|
||||||
|
{{else}}
|
||||||
|
{{.Source}}
|
||||||
|
{{end}}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{end}}
|
||||||
|
</ul>
|
||||||
|
{{end}}
|
||||||
|
</div>
|
34
post.go
34
post.go
|
@ -59,24 +59,24 @@ type IPost interface {
|
||||||
SendWebmention(webmention WebmentionOut) error
|
SendWebmention(webmention WebmentionOut) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type Reply struct {
|
type ReplyData struct {
|
||||||
Url string `yaml:"url"`
|
Url string `yaml:"url"`
|
||||||
Text string `yaml:"text"`
|
Text string `yaml:"text"`
|
||||||
}
|
}
|
||||||
type Bookmark struct {
|
type BookmarkData struct {
|
||||||
Url string `yaml:"url"`
|
Url string `yaml:"url"`
|
||||||
Text string `yaml:"text"`
|
Text string `yaml:"text"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type PostMeta struct {
|
type PostMeta struct {
|
||||||
Type string `yaml:"type"`
|
Type string `yaml:"type"`
|
||||||
Title string `yaml:"title"`
|
Title string `yaml:"title"`
|
||||||
Description string `yaml:"description"`
|
Description string `yaml:"description"`
|
||||||
Aliases []string `yaml:"aliases"`
|
Aliases []string `yaml:"aliases"`
|
||||||
Date time.Time `yaml:"date"`
|
Date time.Time `yaml:"date"`
|
||||||
Draft bool `yaml:"draft"`
|
Draft bool `yaml:"draft"`
|
||||||
Reply Reply `yaml:"reply"`
|
Reply ReplyData `yaml:"reply"`
|
||||||
Bookmark Bookmark `yaml:"bookmark"`
|
Bookmark BookmarkData `yaml:"bookmark"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pm PostMeta) FormattedDate() string {
|
func (pm PostMeta) FormattedDate() string {
|
||||||
|
@ -85,13 +85,13 @@ func (pm PostMeta) FormattedDate() string {
|
||||||
|
|
||||||
func (pm *PostMeta) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
func (pm *PostMeta) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||||
type T struct {
|
type T struct {
|
||||||
Type string `yaml:"type"`
|
Type string `yaml:"type"`
|
||||||
Title string `yaml:"title"`
|
Title string `yaml:"title"`
|
||||||
Description string `yaml:"description"`
|
Description string `yaml:"description"`
|
||||||
Aliases []string `yaml:"aliases"`
|
Aliases []string `yaml:"aliases"`
|
||||||
Draft bool `yaml:"draft"`
|
Draft bool `yaml:"draft"`
|
||||||
Reply Reply `yaml:"reply"`
|
Reply ReplyData `yaml:"reply"`
|
||||||
Bookmark Bookmark `yaml:"bookmark"`
|
Bookmark BookmarkData `yaml:"bookmark"`
|
||||||
}
|
}
|
||||||
type S struct {
|
type S struct {
|
||||||
Date string `yaml:"date"`
|
Date string `yaml:"date"`
|
||||||
|
|
|
@ -23,3 +23,19 @@ type Page struct {
|
||||||
func (p *Page) TemplateDir() string {
|
func (p *Page) TemplateDir() string {
|
||||||
return "page"
|
return "page"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Bookmark struct {
|
||||||
|
Post
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Bookmark) TemplateDir() string {
|
||||||
|
return "bookmark"
|
||||||
|
}
|
||||||
|
|
||||||
|
type Reply struct {
|
||||||
|
Post
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Reply) TemplateDir() string {
|
||||||
|
return "reply"
|
||||||
|
}
|
||||||
|
|
|
@ -180,7 +180,7 @@ func TestIndexPageDoesNotContainsArticle(t *testing.T) {
|
||||||
|
|
||||||
func TestIndexPageDoesNotContainsReply(t *testing.T) {
|
func TestIndexPageDoesNotContainsReply(t *testing.T) {
|
||||||
user := getTestUser()
|
user := getTestUser()
|
||||||
user.CreateNewPostFull(owl.PostMeta{Type: "reply", Reply: owl.Reply{Url: "https://example.com/post"}}, "hi")
|
user.CreateNewPostFull(owl.PostMeta{Type: "reply", Reply: owl.ReplyData{Url: "https://example.com/post"}}, "hi")
|
||||||
|
|
||||||
result, _ := owl.RenderIndexPage(user)
|
result, _ := owl.RenderIndexPage(user)
|
||||||
assertions.AssertContains(t, result, "class=\"h-entry\"")
|
assertions.AssertContains(t, result, "class=\"h-entry\"")
|
||||||
|
@ -301,17 +301,12 @@ func TestAuthorNameInPost(t *testing.T) {
|
||||||
func TestRenderReplyWithoutText(t *testing.T) {
|
func TestRenderReplyWithoutText(t *testing.T) {
|
||||||
|
|
||||||
user := getTestUser()
|
user := getTestUser()
|
||||||
post, _ := user.CreateNewPost("testpost", false)
|
post, _ := user.CreateNewPostFull(owl.PostMeta{
|
||||||
|
Type: "reply",
|
||||||
content := "---\n"
|
Reply: owl.ReplyData{
|
||||||
content += "title: test\n"
|
Url: "https://example.com/post",
|
||||||
content += "date: Wed, 17 Aug 2022 10:50:02 +0000\n"
|
},
|
||||||
content += "reply: \n"
|
}, "Hi ")
|
||||||
content += " url: https://example.com/post\n"
|
|
||||||
content += "---\n"
|
|
||||||
content += "\n"
|
|
||||||
content += "Hi \n"
|
|
||||||
os.WriteFile(post.ContentFile(), []byte(content), 0644)
|
|
||||||
|
|
||||||
result, _ := owl.RenderPost(post)
|
result, _ := owl.RenderPost(post)
|
||||||
assertions.AssertContains(t, result, "https://example.com/post")
|
assertions.AssertContains(t, result, "https://example.com/post")
|
||||||
|
@ -320,17 +315,13 @@ func TestRenderReplyWithoutText(t *testing.T) {
|
||||||
func TestRenderReplyWithText(t *testing.T) {
|
func TestRenderReplyWithText(t *testing.T) {
|
||||||
|
|
||||||
user := getTestUser()
|
user := getTestUser()
|
||||||
post, _ := user.CreateNewPost("testpost", false)
|
post, _ := user.CreateNewPostFull(owl.PostMeta{
|
||||||
|
Type: "reply",
|
||||||
content := "---\n"
|
Reply: owl.ReplyData{
|
||||||
content += "title: test\n"
|
Url: "https://example.com/post",
|
||||||
content += "date: Wed, 17 Aug 2022 10:50:02 +0000\n"
|
Text: "This is a reply",
|
||||||
content += "reply: \n"
|
},
|
||||||
content += " url: https://example.com/post\n"
|
}, "Hi ")
|
||||||
content += " text: \"This is a reply\"\n"
|
|
||||||
content += "---\n"
|
|
||||||
content += "Hi \n"
|
|
||||||
os.WriteFile(post.ContentFile(), []byte(content), 0644)
|
|
||||||
|
|
||||||
result, _ := owl.RenderPost(post)
|
result, _ := owl.RenderPost(post)
|
||||||
assertions.AssertContains(t, result, "https://example.com/post")
|
assertions.AssertContains(t, result, "https://example.com/post")
|
||||||
|
@ -340,7 +331,7 @@ func TestRenderReplyWithText(t *testing.T) {
|
||||||
|
|
||||||
func TestRengerPostContainsBookmark(t *testing.T) {
|
func TestRengerPostContainsBookmark(t *testing.T) {
|
||||||
user := getTestUser()
|
user := getTestUser()
|
||||||
post, _ := user.CreateNewPostFull(owl.PostMeta{Type: "bookmark", Bookmark: owl.Bookmark{Url: "https://example.com/post"}}, "hi")
|
post, _ := user.CreateNewPostFull(owl.PostMeta{Type: "bookmark", Bookmark: owl.BookmarkData{Url: "https://example.com/post"}}, "hi")
|
||||||
|
|
||||||
result, _ := owl.RenderPost(post)
|
result, _ := owl.RenderPost(post)
|
||||||
assertions.AssertContains(t, result, "https://example.com/post")
|
assertions.AssertContains(t, result, "https://example.com/post")
|
||||||
|
|
9
user.go
9
user.go
|
@ -285,14 +285,17 @@ func (user User) GetPost(id string) (IPost, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
post := Post{user: &user, id: id}
|
post := Post{user: &user, id: id}
|
||||||
if post.Meta().Type == "" {
|
|
||||||
return &Article{Post: post}, nil
|
|
||||||
}
|
|
||||||
switch post.Meta().Type {
|
switch post.Meta().Type {
|
||||||
case "article":
|
case "article":
|
||||||
return &Article{Post: post}, nil
|
return &Article{Post: post}, nil
|
||||||
case "note":
|
case "note":
|
||||||
return &Note{Post: post}, nil
|
return &Note{Post: post}, nil
|
||||||
|
case "reply":
|
||||||
|
return &Reply{Post: post}, nil
|
||||||
|
case "bookmark":
|
||||||
|
return &Bookmark{Post: post}, nil
|
||||||
|
case "page":
|
||||||
|
return &Page{Post: post}, nil
|
||||||
}
|
}
|
||||||
return &post, nil
|
return &post, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue