From 2009fa81450801eb721d0aec07b0fa8a01becf00 Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Thu, 14 May 2026 14:49:51 +0100 Subject: [PATCH] knotmirror: add index page just one of those things i would like Signed-off-by: oppiliappan --- knotmirror/adminpage.go | 11 +++++++++++ knotmirror/templates/index.html | 4 ++++ 2 files changed, 15 insertions(+) create mode 100644 knotmirror/templates/index.html diff --git a/knotmirror/adminpage.go b/knotmirror/adminpage.go index 633ac023..4fc3787f 100644 --- a/knotmirror/adminpage.go +++ b/knotmirror/adminpage.go @@ -43,6 +43,7 @@ func NewAdminServer(l *slog.Logger, database *sql.DB, resyncer *Resyncer, x *xrp func (s *AdminServer) Router() http.Handler { r := chi.NewRouter() + r.Get("/", s.handleIndex()) r.Get("/repos", s.handleRepos()) r.Get("/hosts", s.handleHosts()) @@ -79,6 +80,16 @@ func funcmap() template.FuncMap { } } +func (s *AdminServer) handleIndex() http.HandlerFunc { + tpl := template.Must(template.New("").Funcs(funcmap()).ParseFS(templateFS, "templates/base.html", "templates/index.html")) + return func(w http.ResponseWriter, r *http.Request) { + err := tpl.ExecuteTemplate(w, "base", nil) + if err != nil { + slog.Error("failed to render", "err", err) + } + } +} + func (s *AdminServer) handleRepos() http.HandlerFunc { tpl := template.Must(template.New("").Funcs(funcmap()).ParseFS(templateFS, "templates/base.html", "templates/repos.html")) return func(w http.ResponseWriter, r *http.Request) { diff --git a/knotmirror/templates/index.html b/knotmirror/templates/index.html new file mode 100644 index 00000000..c4991358 --- /dev/null +++ b/knotmirror/templates/index.html @@ -0,0 +1,4 @@ +{{template "base" .}} +{{define "content"}} +

Knotmirror

+{{end}} -- 2.51.2