You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
nikita-tokarch-uk/pkg/routes/blog.go

30 lines
659 B

package routes
import (
routing "github.com/jackwhelpton/fasthttp-routing/v2"
"code.tokarch.uk/mainnika/nikita-tokarch-uk/pkg/content"
"code.tokarch.uk/mainnika/nikita-tokarch-uk/pkg/ghost/params"
)
// blog handler renders blog data
func (r *Routes) blog(c *routing.Context) (err error) {
postsPerPage := r.ContentConfig.PostsPerPage
currentPage := c.QueryArgs().GetUintOrZero("page")
latestPosts, err := r.GhostClient.GetPosts(
params.WithLimit(postsPerPage),
params.WithPage(currentPage),
)
if err != nil {
return
}
blogContent := content.Blog{
Meta: latestPosts.Meta,
Posts: latestPosts.Posts,
}
return c.Write(blogContent)
}