diff --git a/frontend/content/blog.go b/frontend/content/blog.go index 5668e36..20be021 100644 --- a/frontend/content/blog.go +++ b/frontend/content/blog.go @@ -1,6 +1,13 @@ package content +import ( + "code.tokarch.uk/mainnika/nikita-tokarch-uk/frontend/ghost" +) + // Blog content data type Blog struct { _ interface{} `template:"blog.go.tmpl"` + ghost.Meta + Pinned []ghost.Post + Posts []ghost.Post } diff --git a/frontend/renderer/blog.go b/frontend/renderer/blog.go index 0617aac..f2d417d 100644 --- a/frontend/renderer/blog.go +++ b/frontend/renderer/blog.go @@ -2,13 +2,24 @@ package renderer import ( "code.tokarch.uk/mainnika/nikita-tokarch-uk/frontend/content" + "code.tokarch.uk/mainnika/nikita-tokarch-uk/frontend/ghost" routing "github.com/jackwhelpton/fasthttp-routing/v2" ) // blog handler renders blog data func (r *Renderer) blog(c *routing.Context) (err error) { + postsPerPage := r.ContentConfig.PostsPerPage + currentPage := c.QueryArgs().GetUintOrZero("page") + + latestPosts, err := r.GhostClient.GetPosts(ghost.QueryLimit(postsPerPage), ghost.QueryPage(currentPage)) + if err != nil { + return + } + blogContent := content.Blog{ + Meta: latestPosts.Meta, + Posts: latestPosts.Posts, } return c.Write(blogContent)