add reply-to url. #22
This commit is contained in:
parent
4cc69ff257
commit
9056b22536
|
@ -15,6 +15,19 @@
|
|||
</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>
|
||||
|
|
10
post.go
10
post.go
|
@ -27,11 +27,17 @@ type Post struct {
|
|||
wmLock sync.Mutex
|
||||
}
|
||||
|
||||
type Reply struct {
|
||||
Url string `yaml:"url"`
|
||||
Text string `yaml:"text"`
|
||||
}
|
||||
|
||||
type PostMeta struct {
|
||||
Title string `yaml:"title"`
|
||||
Aliases []string `yaml:"aliases"`
|
||||
Date time.Time `yaml:"date"`
|
||||
Draft bool `yaml:"draft"`
|
||||
Reply Reply `yaml:"reply"`
|
||||
}
|
||||
|
||||
func (pm PostMeta) FormattedDate() string {
|
||||
|
@ -43,6 +49,7 @@ func (pm *PostMeta) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|||
Title string `yaml:"title"`
|
||||
Aliases []string `yaml:"aliases"`
|
||||
Draft bool `yaml:"draft"`
|
||||
Reply Reply `yaml:"reply"`
|
||||
}
|
||||
type S struct {
|
||||
Date string `yaml:"date"`
|
||||
|
@ -60,6 +67,7 @@ func (pm *PostMeta) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|||
pm.Title = t.Title
|
||||
pm.Aliases = t.Aliases
|
||||
pm.Draft = t.Draft
|
||||
pm.Reply = t.Reply
|
||||
|
||||
possibleFormats := []string{
|
||||
"2006-01-02",
|
||||
|
@ -206,7 +214,7 @@ func (post *Post) LoadMeta() error {
|
|||
if string(trimmedData[0:4]) == "---\n" {
|
||||
trimmedData = trimmedData[4:]
|
||||
// find --- end
|
||||
end := bytes.Index(trimmedData, []byte("\n---\n"))
|
||||
end := bytes.Index(trimmedData, []byte("---\n"))
|
||||
if end != -1 {
|
||||
metaData := trimmedData[:end]
|
||||
err := yaml.Unmarshal(metaData, &meta)
|
||||
|
|
|
@ -277,3 +277,49 @@ func TestAuthorNameInPost(t *testing.T) {
|
|||
t.Error("Author Name not included. Got: " + result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderReplyWithoutText(t *testing.T) {
|
||||
|
||||
user := getTestUser()
|
||||
post, _ := user.CreateNewPost("testpost")
|
||||
|
||||
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)
|
||||
|
||||
result, _ := owl.RenderPost(&post)
|
||||
if !strings.Contains(result, "https://example.com/post") {
|
||||
t.Error("Reply url not rendered. Got: " + result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderReplyWithText(t *testing.T) {
|
||||
|
||||
user := getTestUser()
|
||||
post, _ := user.CreateNewPost("testpost")
|
||||
|
||||
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)
|
||||
|
||||
result, _ := owl.RenderPost(&post)
|
||||
if !strings.Contains(result, "https://example.com/post") {
|
||||
t.Error("Reply url not rendered. Got: " + result)
|
||||
}
|
||||
|
||||
if !strings.Contains(result, "This is a reply") {
|
||||
t.Error("Reply text not rendered. Got: " + result)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue