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