28 lines
494 B
Go
28 lines
494 B
Go
package handlers
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/gofiber/fiber/v3"
|
|
"lmika.dev/lmika/hugo-cms/services/sites"
|
|
)
|
|
|
|
type IndexHandler struct {
|
|
Sites *sites.Service
|
|
}
|
|
|
|
func (h IndexHandler) Index(c fiber.Ctx) error {
|
|
prefs := GetPrefCookie(c)
|
|
if prefs.SiteID > 0 {
|
|
return c.Redirect().To(fmt.Sprintf("/sites/%v/posts", prefs.SiteID))
|
|
}
|
|
|
|
sites, err := h.Sites.ListSites(c.Context())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return c.Render("index", fiber.Map{
|
|
"sites": sites,
|
|
}, "layouts/main")
|
|
}
|