From aa63d26cdd4284faf67f9582d34a12c8767aed15 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Mon, 18 Aug 2025 02:09:50 +0800 Subject: Add template rendering --- forged/internal/incoming/web/handlers/repo/index.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'forged/internal/incoming/web/handlers/repo/index.go') diff --git a/forged/internal/incoming/web/handlers/repo/index.go b/forged/internal/incoming/web/handlers/repo/index.go index 3a6d7ea..dd1382f 100644 --- a/forged/internal/incoming/web/handlers/repo/index.go +++ b/forged/internal/incoming/web/handlers/repo/index.go @@ -1,20 +1,28 @@ package repo import ( - "fmt" "net/http" "strings" + "go.lindenii.runxiyu.org/forge/forged/internal/incoming/web/templates" wtypes "go.lindenii.runxiyu.org/forge/forged/internal/incoming/web/types" ) -type HTTP struct{} +type HTTP struct { + r templates.Renderer +} -func NewHTTP() *HTTP { return &HTTP{} } +func NewHTTP(r templates.Renderer) *HTTP { return &HTTP{r: r} } func (h *HTTP) Index(w http.ResponseWriter, r *http.Request, v wtypes.Vars) { base := wtypes.Base(r) repo := v["repo"] - _, _ = w.Write([]byte(fmt.Sprintf("repo index: group=%q repo=%q", - "/"+strings.Join(base.GroupPath, "/")+"/", repo))) + _ = h.r.Render(w, "repo/index.html", struct { + Group string + Repo string + }{ + Group: "/" + strings.Join(base.GroupPath, "/") + "/", + Repo: repo, + }) } + -- cgit v1.2.3