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
+7
View File
@@ -1,6 +1,13 @@
package content package content
import (
"code.tokarch.uk/mainnika/nikita-tokarch-uk/frontend/ghost"
)
// Index content data // Index content data
type Index struct { type Index struct {
_ interface{} `template:"index.go.tmpl"` _ interface{} `template:"index.go.tmpl"`
ghost.Meta
Pinned []ghost.Post
Posts []ghost.Post
} }
+17
View File
@@ -4,6 +4,7 @@ import (
"net/http" "net/http"
"code.tokarch.uk/mainnika/nikita-tokarch-uk/frontend/content" "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" "code.tokarch.uk/mainnika/nikita-tokarch-uk/frontend/templates"
routing "github.com/jackwhelpton/fasthttp-routing/v2" 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 // index handler renders index data
func (r *Renderer) index(c *routing.Context) (err error) { 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{ indexContent := content.Index{
Pinned: pinnedPages.Pages,
Meta: latestPosts.Meta,
Posts: latestPosts.Posts,
} }
return c.Write(indexContent) return c.Write(indexContent)