more types

This commit is contained in:
Niko Abeler 2022-12-05 20:31:48 +01:00
parent b61e2ff50c
commit 1fefa2a140
11 changed files with 261 additions and 84 deletions

View File

@ -251,10 +251,10 @@ func userEditorPostHandler(repo *owl.Repository) func(http.ResponseWriter, *http
Description: description,
Draft: draft == "on",
Date: time.Now(),
Reply: owl.Reply{
Reply: owl.ReplyData{
Url: reply_url,
},
Bookmark: owl.Bookmark{
Bookmark: owl.BookmarkData{
Url: bookmark_url,
},
}, content)

View File

@ -336,7 +336,7 @@ func userMicropubHandler(repo *owl.Repository) func(http.ResponseWriter, *http.R
post, err := user.CreateNewPostFull(
owl.PostMeta{
Title: name,
Reply: owl.Reply{
Reply: owl.ReplyData{
Url: inReplyTo,
},
Date: time.Now(),

View File

@ -22,18 +22,6 @@
<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}}">

View File

@ -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>

View File

@ -1,6 +1,5 @@
<div class="h-entry">
<hgroup>
<h1 class="p-name">{{.Title}}</h1>
<small>
<a class="u-url" href="{{.Post.FullUrl}}">#</a>
Published:
@ -22,30 +21,6 @@
<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>

60
embed/reply/detail.html Normal file
View File

@ -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>

72
embed/untyped/detail.html Normal file
View File

@ -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>

12
post.go
View File

@ -59,11 +59,11 @@ type IPost interface {
SendWebmention(webmention WebmentionOut) error
}
type Reply struct {
type ReplyData struct {
Url string `yaml:"url"`
Text string `yaml:"text"`
}
type Bookmark struct {
type BookmarkData struct {
Url string `yaml:"url"`
Text string `yaml:"text"`
}
@ -75,8 +75,8 @@ type PostMeta struct {
Aliases []string `yaml:"aliases"`
Date time.Time `yaml:"date"`
Draft bool `yaml:"draft"`
Reply Reply `yaml:"reply"`
Bookmark Bookmark `yaml:"bookmark"`
Reply ReplyData `yaml:"reply"`
Bookmark BookmarkData `yaml:"bookmark"`
}
func (pm PostMeta) FormattedDate() string {
@ -90,8 +90,8 @@ func (pm *PostMeta) UnmarshalYAML(unmarshal func(interface{}) error) error {
Description string `yaml:"description"`
Aliases []string `yaml:"aliases"`
Draft bool `yaml:"draft"`
Reply Reply `yaml:"reply"`
Bookmark Bookmark `yaml:"bookmark"`
Reply ReplyData `yaml:"reply"`
Bookmark BookmarkData `yaml:"bookmark"`
}
type S struct {
Date string `yaml:"date"`

View File

@ -23,3 +23,19 @@ type Page struct {
func (p *Page) TemplateDir() string {
return "page"
}
type Bookmark struct {
Post
}
func (b *Bookmark) TemplateDir() string {
return "bookmark"
}
type Reply struct {
Post
}
func (r *Reply) TemplateDir() string {
return "reply"
}

View File

@ -180,7 +180,7 @@ func TestIndexPageDoesNotContainsArticle(t *testing.T) {
func TestIndexPageDoesNotContainsReply(t *testing.T) {
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)
assertions.AssertContains(t, result, "class=\"h-entry\"")
@ -301,17 +301,12 @@ func TestAuthorNameInPost(t *testing.T) {
func TestRenderReplyWithoutText(t *testing.T) {
user := getTestUser()
post, _ := user.CreateNewPost("testpost", false)
content := "---\n"
content += "title: test\n"
content += "date: Wed, 17 Aug 2022 10:50:02 +0000\n"
content += "reply: \n"
content += " url: https://example.com/post\n"
content += "---\n"
content += "\n"
content += "Hi \n"
os.WriteFile(post.ContentFile(), []byte(content), 0644)
post, _ := user.CreateNewPostFull(owl.PostMeta{
Type: "reply",
Reply: owl.ReplyData{
Url: "https://example.com/post",
},
}, "Hi ")
result, _ := owl.RenderPost(post)
assertions.AssertContains(t, result, "https://example.com/post")
@ -320,17 +315,13 @@ func TestRenderReplyWithoutText(t *testing.T) {
func TestRenderReplyWithText(t *testing.T) {
user := getTestUser()
post, _ := user.CreateNewPost("testpost", false)
content := "---\n"
content += "title: test\n"
content += "date: Wed, 17 Aug 2022 10:50:02 +0000\n"
content += "reply: \n"
content += " url: https://example.com/post\n"
content += " text: \"This is a reply\"\n"
content += "---\n"
content += "Hi \n"
os.WriteFile(post.ContentFile(), []byte(content), 0644)
post, _ := user.CreateNewPostFull(owl.PostMeta{
Type: "reply",
Reply: owl.ReplyData{
Url: "https://example.com/post",
Text: "This is a reply",
},
}, "Hi ")
result, _ := owl.RenderPost(post)
assertions.AssertContains(t, result, "https://example.com/post")
@ -340,7 +331,7 @@ func TestRenderReplyWithText(t *testing.T) {
func TestRengerPostContainsBookmark(t *testing.T) {
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)
assertions.AssertContains(t, result, "https://example.com/post")

View File

@ -285,14 +285,17 @@ func (user User) GetPost(id string) (IPost, error) {
}
post := Post{user: &user, id: id}
if post.Meta().Type == "" {
return &Article{Post: post}, nil
}
switch post.Meta().Type {
case "article":
return &Article{Post: post}, nil
case "note":
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
}