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.
45 lines
1015 B
45 lines
1015 B
3 years ago
|
package routes
|
||
3 years ago
|
|
||
|
import (
|
||
3 years ago
|
"net/http"
|
||
|
|
||
3 years ago
|
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"
|
||
|
"code.tokarch.uk/mainnika/nikita-tokarch-uk/pkg/templates"
|
||
3 years ago
|
)
|
||
|
|
||
3 years ago
|
// rootRedirect redirects the root url to the index using http redirect
|
||
3 years ago
|
func (r *Routes) rootRedirect(c *routing.Context) (err error) {
|
||
3 years ago
|
|
||
|
c.Redirect(templates.URLIndex, http.StatusFound)
|
||
|
|
||
|
return
|
||
|
}
|
||
|
|
||
3 years ago
|
// index handler renders index data
|
||
3 years ago
|
func (r *Routes) index(c *routing.Context) (err error) {
|
||
3 years ago
|
|
||
3 years ago
|
pinnedPageSlug := r.ContentConfig.Pinned
|
||
|
postsPerPage := r.ContentConfig.PostsPerPage
|
||
|
|
||
|
pinnedPages, err := r.GhostClient.GetPageBySlug(pinnedPageSlug)
|
||
|
if err != nil {
|
||
|
return
|
||
|
}
|
||
|
|
||
3 years ago
|
latestPosts, err := r.GhostClient.GetPosts(params.WithLimit(postsPerPage))
|
||
3 years ago
|
if err != nil {
|
||
|
return
|
||
|
}
|
||
|
|
||
3 years ago
|
indexContent := content.Index{
|
||
3 years ago
|
Pinned: pinnedPages.Pages,
|
||
|
Meta: latestPosts.Meta,
|
||
|
Posts: latestPosts.Posts,
|
||
3 years ago
|
}
|
||
|
|
||
|
return c.Write(indexContent)
|
||
|
}
|