feat: translation middleware

This commit is contained in:
2026-02-19 21:13:01 +01:00
parent bbae5b1c93
commit cbc2a1a803
35 changed files with 1500 additions and 82 deletions
+28
View File
@@ -0,0 +1,28 @@
package layouts
import (
"context"
"fmt"
"io"
"log/slog"
"net/http"
"github.com/a-h/templ"
)
// Render renders a page. If the query paramenter "c" is set
// the component gets rendered without the layout
func Render(ctx context.Context, w io.Writer, r *http.Request, component templ.Component) {
withLayout := !r.URL.Query().Has("c")
fmt.Println("layout: ", withLayout)
slog.Debug("HX-Request", "value", r.Header.Get("HX-Request"))
if r.Header.Get("HX-Request") != "true" {
ctx = templ.WithChildren(ctx, component)
component = Base("hello")
}
if err := component.Render(ctx, w); err != nil {
slog.Error("error while rendering component", "err", err, "ctx", ctx)
}
}