Compare commits

...
1 Commits
Author SHA1 Message Date
schreifuchs 297efaa4a6 fix(translations): stay on page
release.yaml / publish (push) Successful in 4m0s
2026-09-28 09:52:22 +02:00
3 changed files with 45 additions and 24 deletions

No files matched your search

+8
View File
@@ -53,13 +53,21 @@ func Path(ctx context.Context, pp ...string) string {
}
func PathForLang(ctx context.Context, lang string, pp ...string) string {
slog.Debug("computing path for lang", "pp", pp, "lang", lang)
s, ok := ctx.Value(serviceKey).(*Service)
if !ok {
slog.Error("could not extract translation service from context for translating path", "ctx", ctx, "path", pp)
return path.Join(pp...)
}
// remove leading ""
for len(pp) > 0 && pp[0] == "" {
pp = pp[1:]
}
if len(pp) > 0 {
slog.Debug("computing path for lang", "pp", pp, "lang", lang, "pp[0]", pp[0], "translations", s.translations)
if _, ok := s.translations[pp[0]]; ok {
pp = pp[1:]
}
+36 -23
View File
@@ -7,7 +7,7 @@ import (
"strings"
)
templ Head(cfg config.Cfg, title string) {
templ head(cfg config.Cfg, title string) {
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
@@ -29,29 +29,42 @@ templ Head(cfg config.Cfg, title string) {
templ Base(cfg config.Cfg, title string) {
<!DOCTYPE html>
<html lang={ translate.Language(ctx) }>
@Head(cfg, title)
<body class="bg-black dark" hx-boost="true" hx-target="main" hx-ext="head-support,preload,preload-links">
<header
class="fixed z-50 mix-blend-difference p-1 w-full flex justify-between items-start"
>
<a class="text-white text-2xl" href={ translate.Path(ctx, "") } preload="mouseover" preload-images="true">schreifuchs.ch</a>
<nav class="flex gap-2 p-2">
for _, lang := range translate.SupportedLanguages(ctx) {
<a
href={ translate.PathForLang(ctx, lang, strings.Split(templer.Path(ctx), "/")...) }
hreflang={ lang }
data-no-translate
preload="mouseover"
class="text-white hover:underline uppercase"
>
{ lang }
</a>
}
</nav>
</header>
<main class="text-white">
@head(cfg, title)
<body class="bg-black dark" hx-boost="true" hx-target="body" hx-ext="head-support,preload,preload-links">
@body() {
{ children... }
</main>
}
</body>
</html>
}
templ Content(cfg config.Cfg, title string) {
@head(cfg, title)
@body() {
{ children... }
}
}
templ body() {
<header
class="fixed z-50 mix-blend-difference p-1 w-full flex justify-between items-start"
>
<a class="text-white text-2xl" href={ translate.Path(ctx, "") } preload="mouseover" preload-images="true">schreifuchs.ch</a>
<nav class="flex gap-2 p-2">
for _, lang := range translate.SupportedLanguages(ctx) {
<a
href={ translate.PathForLang(ctx, lang, strings.Split(templer.Path(ctx), "/")...) }
hreflang={ lang }
data-no-translate
preload="mouseover"
class="text-white hover:underline uppercase"
>
{ lang }
</a>
}
</nav>
</header>
<main class="text-white">
{ children... }
</main>
}
+1 -1
View File
@@ -36,7 +36,7 @@ func (l *Layouts) Render(ctx context.Context, w io.Writer, r *http.Request, comp
component = Base(l.cfg, title)
} else {
ctx = templ.WithChildren(ctx, component)
component = Head(l.cfg, title)
component = Content(l.cfg, title)
}
if err := component.Render(ctx, w); err != nil {