mirror of
https://github.com/mainnika/nikita-tokarch-uk.git
synced 2026-05-25 01:03:35 +00:00
Load index page data as the content
This commit is contained in:
@@ -1,6 +1,13 @@
|
||||
package content
|
||||
|
||||
import (
|
||||
"code.tokarch.uk/mainnika/nikita-tokarch-uk/frontend/ghost"
|
||||
)
|
||||
|
||||
// Index content data
|
||||
type Index struct {
|
||||
_ interface{} `template:"index.go.tmpl"`
|
||||
ghost.Meta
|
||||
Pinned []ghost.Post
|
||||
Posts []ghost.Post
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user