diff options
author | Alexander Neonxp Kiryukhin <i@neonxp.ru> | 2024-10-07 04:18:59 +0300 |
---|---|---|
committer | Alexander Neonxp Kiryukhin <i@neonxp.ru> | 2024-10-07 04:18:59 +0300 |
commit | 895c7905f9e39bbb046c130a3a94e4044bf6c989 (patch) | |
tree | fb9b458237f2f3553e0f9b93fa0d70f12f786185 /pkg/handler/random.go | |
parent | ffcc9eeb1746971d7d009822ae65a1201c54e289 (diff) |
Подгрузка рандома аяксом
Diffstat (limited to 'pkg/handler/random.go')
-rw-r--r-- | pkg/handler/random.go | 15 |
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()) } |