Load index page data as the content

This commit is contained in:
2021-12-03 04:04:46 +01:00
parent ea58971e86
commit 47029b5a4c
2 changed files with 24 additions and 0 deletions
+17
View File
@@ -4,6 +4,7 @@ import (
"net/http"
"code.tokarch.uk/mainnika/nikita-tokarch-uk/frontend/content"
"code.tokarch.uk/mainnika/nikita-tokarch-uk/frontend/ghost"
"code.tokarch.uk/mainnika/nikita-tokarch-uk/frontend/templates"
routing "github.com/jackwhelpton/fasthttp-routing/v2"
)
@@ -19,7 +20,23 @@ func (r *Renderer) rootRedirect(c *routing.Context) (err error) {
// index handler renders index data
func (r *Renderer) index(c *routing.Context) (err error) {
pinnedPageSlug := r.ContentConfig.Pinned
postsPerPage := r.ContentConfig.PostsPerPage
pinnedPages, err := r.GhostClient.GetPageBySlug(pinnedPageSlug)
if err != nil {
return
}
latestPosts, err := r.GhostClient.GetPosts(ghost.QueryLimit(postsPerPage))
if err != nil {
return
}
indexContent := content.Index{
Pinned: pinnedPages.Pages,
Meta: latestPosts.Meta,
Posts: latestPosts.Posts,
}
return c.Write(indexContent)