Load index page data as the content

pull/1/head
Nikita Tokarchuk 3 years ago
parent ea58971e86
commit 47029b5a4c
Signed by: mainnika
GPG Key ID: A595FB7E3E56911C
  1. 7
      frontend/content/index.go
  2. 17
      frontend/renderer/index.go

@ -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
} }

@ -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)

Loading…
Cancel
Save