mirror of
https://github.com/mainnika/nikita-tokarch-uk.git
synced 2026-05-25 01:03:35 +00:00
Handle custom urls by using ghost-slug id
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
@@ -4,6 +4,7 @@ const (
|
||||
URLPostfix = "aspx"
|
||||
|
||||
URLRoot = "/"
|
||||
URLSlug = "/<slug:[^/\\.]*>." + URLPostfix
|
||||
URLIndex = "/index." + URLPostfix
|
||||
URLBlog = "/blog." + URLPostfix
|
||||
URLPost = "/post." + URLPostfix
|
||||
|
||||
Reference in New Issue
Block a user