Add content title and description helpers

This commit is contained in:
2021-12-03 04:07:46 +01:00
parent 7a694bcbe8
commit f3ed0ccc0a
3 changed files with 40 additions and 0 deletions
+12
View File
@@ -1,6 +1,8 @@
package content package content
import ( import (
"fmt"
"code.tokarch.uk/mainnika/nikita-tokarch-uk/frontend/ghost" "code.tokarch.uk/mainnika/nikita-tokarch-uk/frontend/ghost"
) )
@@ -11,3 +13,13 @@ type Blog struct {
Pinned []ghost.Post Pinned []ghost.Post
Posts []ghost.Post Posts []ghost.Post
} }
// Title returns blog content title
func (i Blog) Title() string {
return fmt.Sprintf("... %d of %d", i.Meta.Pagination.Page, i.Meta.Pagination.Pages)
}
// Description returns blog content description
func (i Blog) Description() string {
return "TODO:"
}
+10
View File
@@ -6,3 +6,13 @@ type Error struct {
Message string Message string
} }
// Title returns error title
func (e Error) Title() string {
return e.Message
}
// Description returns error description
func (e Error) Description() string {
return e.Message
}
+18
View File
@@ -11,3 +11,21 @@ type Index struct {
Pinned []ghost.Post Pinned []ghost.Post
Posts []ghost.Post Posts []ghost.Post
} }
// Title returns index title
func (i Index) Title() string {
if len(i.Pinned) > 0 {
return i.Pinned[0].Title
}
if len(i.Posts) > 0 {
return i.Posts[0].Title
}
return "UNKNOWN:"
}
// Description returns index description
func (i Index) Description() string {
return "TODO:"
}