Handle custom urls by using ghost-slug id

This commit is contained in:
2022-01-26 04:46:18 +01:00
parent 1e6cbd574f
commit dfe60f241a
3 changed files with 32 additions and 0 deletions
+1
View File
@@ -44,6 +44,7 @@ func (r *Routes) init() {
root.Get(templates.URLRoot, r.rootRedirect)
root.Get(templates.URLIndex, r.index)
root.Get(templates.URLBlog, r.blog)
root.Get(templates.URLSlug, r.slug)
r.router = router
r.handler = router.HandleRequest
+30
View File
@@ -0,0 +1,30 @@
package routes
import (
"net/http"
routing "github.com/jackwhelpton/fasthttp-routing/v2"
"code.tokarch.uk/mainnika/nikita-tokarch-uk/pkg/content"
)
// slug renders page by its slug
func (r *Routes) slug(c *routing.Context) (err error) {
pageSlug := c.Param("slug")
if pageSlug == "" {
return routing.NewHTTPError(http.StatusNotFound)
}
page, err := r.GhostClient.GetPageBySlug(pageSlug)
if err != nil {
return
}
pageContent := content.Blog{
Meta: page.Meta,
Posts: page.Pages,
}
return c.Write(pageContent)
}