From 7a694bcbe8d28b17283fe804773e8ca12d9526e1 Mon Sep 17 00:00:00 2001 From: Nikita Tokarchuk Date: Fri, 3 Dec 2021 04:05:29 +0100 Subject: [PATCH] Load blog page data as the content --- frontend/content/blog.go | 7 +++++++ frontend/renderer/blog.go | 11 +++++++++++ 2 files changed, 18 insertions(+) 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)