aboutsummaryrefslogtreecommitdiff
path: root/pkg/handler/random.go
diff options
context:
space:
mode:
authorAlexander Neonxp Kiryukhin <i@neonxp.ru>2024-10-07 04:18:59 +0300
committerAlexander Neonxp Kiryukhin <i@neonxp.ru>2024-10-07 04:18:59 +0300
commit895c7905f9e39bbb046c130a3a94e4044bf6c989 (patch)
treefb9b458237f2f3553e0f9b93fa0d70f12f786185 /pkg/handler/random.go
parentffcc9eeb1746971d7d009822ae65a1201c54e289 (diff)
Подгрузка рандома аяксом
Diffstat (limited to 'pkg/handler/random.go')
-rw-r--r--pkg/handler/random.go15
1 files changed, 14 insertions, 1 deletions
diff --git a/pkg/handler/random.go b/pkg/handler/random.go
index 091058f..29c5f6f 100644
--- a/pkg/handler/random.go
+++ b/pkg/handler/random.go
@@ -1,6 +1,7 @@
package handler
import (
+ "github.com/a-h/templ"
"github.com/labstack/echo/v4"
"sh.org.ru/pkg/model"
"sh.org.ru/pkg/tpl"
@@ -14,5 +15,17 @@ func (h *Handler) Random(c echo.Context) error {
return err
}
- return tpl.Random(quotes).Render(c.Request().Context(), c.Response())
+ comp := tpl.Random(quotes)
+
+ if c.Request().Header.Get("Hx-Request") == "true" {
+ return comp.Render(c.Request().Context(), c.Response())
+ }
+
+ ctx := templ.WithChildren(c.Request().Context(), comp)
+
+ return tpl.Layout(tpl.HeaderParams{
+ Title: "Цитатник Рунета",
+ Description: "Новый цитатник Рунета",
+ URL: "https://sh.org.ru/",
+ }).Render(ctx, c.Response())
}