Compare commits

...
2 Commits
Author SHA1 Message Date
schreifuchs 812891a205 fix(gallery): use component template
release.yaml / publish (push) Successful in 3m51s
2026-09-29 10:46:45 +02:00
schreifuchs 297efaa4a6 fix(translations): stay on page
release.yaml / publish (push) Successful in 4m0s
2026-09-28 09:52:22 +02:00
8 changed files with 61 additions and 19 deletions

No files matched your search

+8
View File
@@ -27,3 +27,11 @@ jobs:
file: ./Dockerfile file: ./Dockerfile
push: true push: true
tags: "git.schreifuchs.ch/schreifuchs/schreifuchs.ch:${{ github.ref_name }},git.schreifuchs.ch/schreifuchs/schreifuchs.ch:latest" tags: "git.schreifuchs.ch/schreifuchs/schreifuchs.ch:${{ github.ref_name }},git.schreifuchs.ch/schreifuchs/schreifuchs.ch:latest"
- name: Create Gitea Release
uses: https://gitea.com/actions/gitea-release-action@v1
with:
state: "published"
title: "Release ${{ github.ref_name }}"
notes: "Automated release for tag ${{ github.ref_name }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+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 { 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) s, ok := ctx.Value(serviceKey).(*Service)
if !ok { if !ok {
slog.Error("could not extract translation service from context for translating path", "ctx", ctx, "path", pp) slog.Error("could not extract translation service from context for translating path", "ctx", ctx, "path", pp)
return path.Join(pp...) return path.Join(pp...)
} }
// remove leading ""
for len(pp) > 0 && pp[0] == "" {
pp = pp[1:]
}
if len(pp) > 0 { 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 { if _, ok := s.translations[pp[0]]; ok {
pp = pp[1:] pp = pp[1:]
} }
+2 -2
View File
@@ -27,7 +27,7 @@ func (h *Handler) gallery(w http.ResponseWriter, r *http.Request) {
ctx = templer.AppendHeader(ctx, fmt.Sprintf(`<link rel="preload" href="%s?w=800" as="image" />`, image.URL())) ctx = templer.AppendHeader(ctx, fmt.Sprintf(`<link rel="preload" href="%s?w=800" as="image" />`, image.URL()))
} }
h.r.Render(ctx, w, r, pages.GallerySet(imgs)) h.r.RenderPage(ctx, w, r, pages.GallerySet(imgs))
} }
func (h *Handler) image(w http.ResponseWriter, r *http.Request) { func (h *Handler) image(w http.ResponseWriter, r *http.Request) {
@@ -41,5 +41,5 @@ func (h *Handler) image(w http.ResponseWriter, r *http.Request) {
return return
} }
h.r.Render(r.Context(), w, r, pages.GalleryImage(uid, next, prev)) h.r.RenderComponent(r.Context(), w, r, pages.GalleryImage(uid, next, prev))
} }
+2 -1
View File
@@ -40,5 +40,6 @@ type galleryService interface {
GetPrevAndNext(ctx context.Context, uid string) (previous *gallery.Image, next *gallery.Image, err error) GetPrevAndNext(ctx context.Context, uid string) (previous *gallery.Image, next *gallery.Image, err error)
} }
type renderer interface { type renderer interface {
Render(ctx context.Context, w io.Writer, r *http.Request, component templ.Component) RenderPage(ctx context.Context, w io.Writer, r *http.Request, component templ.Component)
RenderComponent(ctx context.Context, w io.Writer, r *http.Request, component templ.Component)
} }
+2 -2
View File
@@ -17,7 +17,7 @@ func (h *Handler) home(w http.ResponseWriter, r *http.Request) {
return return
} }
h.r.Render(r.Context(), w, r, pages.Home(pageHeaders)) h.r.RenderPage(r.Context(), w, r, pages.Home(pageHeaders))
} }
func (h *Handler) page(w http.ResponseWriter, r *http.Request) { func (h *Handler) page(w http.ResponseWriter, r *http.Request) {
@@ -43,5 +43,5 @@ func (h *Handler) page(w http.ResponseWriter, r *http.Request) {
ctx = templer.PageTitle(ctx, page.Title) ctx = templer.PageTitle(ctx, page.Title)
h.r.Render(ctx, w, r, pages.ContentPage(page)) h.r.RenderPage(ctx, w, r, pages.ContentPage(page))
} }
+1 -1
View File
@@ -33,5 +33,5 @@ type pageService interface {
GetPage(ctx context.Context, uid string) (page.Page, error) GetPage(ctx context.Context, uid string) (page.Page, error)
} }
type renderer interface { type renderer interface {
Render(ctx context.Context, w io.Writer, r *http.Request, component templ.Component) RenderPage(ctx context.Context, w io.Writer, r *http.Request, component templ.Component)
} }
+25 -6
View File
@@ -7,7 +7,7 @@ import (
"strings" "strings"
) )
templ Head(cfg config.Cfg, title string) { templ head(cfg config.Cfg, title string) {
<head> <head>
<meta charset="UTF-8"/> <meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
@@ -23,14 +23,35 @@ templ Head(cfg config.Cfg, title string) {
@templ.Raw(h) @templ.Raw(h)
} }
</head> </head>
{ children... }
} }
templ Base(cfg config.Cfg, title string) { templ Base(cfg config.Cfg, title string) {
<!DOCTYPE html> <!DOCTYPE html>
<html lang={ translate.Language(ctx) }> <html lang={ translate.Language(ctx) }>
@Head(cfg, title) @head(cfg, title)
<body class="bg-black dark" hx-boost="true" hx-target="main" hx-ext="head-support,preload,preload-links"> <body class="bg-black dark" hx-boost="true" hx-target="body" hx-ext="head-support,preload,preload-links">
@body() {
{ children... }
}
</body>
</html>
}
templ Page(cfg config.Cfg, title string) {
@head(cfg, title)
@body() {
{ children... }
}
}
templ Component() {
for _, h := range templer.GetHeader(ctx) {
@templ.Raw(h)
}
{ children... }
}
templ body() {
<header <header
class="fixed z-50 mix-blend-difference p-1 w-full flex justify-between items-start" class="fixed z-50 mix-blend-difference p-1 w-full flex justify-between items-start"
> >
@@ -52,6 +73,4 @@ templ Base(cfg config.Cfg, title string) {
<main class="text-white"> <main class="text-white">
{ children... } { children... }
</main> </main>
</body>
</html>
} }
+13 -7
View File
@@ -2,7 +2,6 @@ package layouts
import ( import (
"context" "context"
"fmt"
"io" "io"
"log/slog" "log/slog"
"net/http" "net/http"
@@ -22,12 +21,9 @@ func New(cfg config.Cfg) *Layouts {
} }
} }
// Render renders a page. If the query paramenter "c" is set // RenderPage renders a page. If the query paramenter HX-Request is set
// the component gets rendered without the layout // the component gets rendered without the layout
func (l *Layouts) Render(ctx context.Context, w io.Writer, r *http.Request, component templ.Component) { func (l *Layouts) RenderPage(ctx context.Context, w io.Writer, r *http.Request, component templ.Component) {
withLayout := !r.URL.Query().Has("c")
fmt.Println("layout: ", withLayout)
title := templer.GetTitle(ctx, "Schreifuchs") title := templer.GetTitle(ctx, "Schreifuchs")
slog.Debug("HX-Request", "value", r.Header.Get("HX-Request")) slog.Debug("HX-Request", "value", r.Header.Get("HX-Request"))
@@ -36,10 +32,20 @@ func (l *Layouts) Render(ctx context.Context, w io.Writer, r *http.Request, comp
component = Base(l.cfg, title) component = Base(l.cfg, title)
} else { } else {
ctx = templ.WithChildren(ctx, component) ctx = templ.WithChildren(ctx, component)
component = Head(l.cfg, title) component = Page(l.cfg, title)
} }
if err := component.Render(ctx, w); err != nil { if err := component.Render(ctx, w); err != nil {
slog.Error("error while rendering component", "err", err, "ctx", ctx) slog.Error("error while rendering component", "err", err, "ctx", ctx)
} }
} }
// RenderComponent renders a component alone.
func (l *Layouts) RenderComponent(ctx context.Context, w io.Writer, r *http.Request, component templ.Component) {
ctx = templ.WithChildren(ctx, component)
component = Component()
if err := component.Render(ctx, w); err != nil {
slog.Error("error while rendering component", "err", err, "ctx", ctx)
}
}