From ea3eba180b209f61290814bcd279a13e38c04671 Mon Sep 17 00:00:00 2001 From: Anya Tokugawa Date: Sun, 31 May 2026 23:39:12 +0900 Subject: [PATCH] Improved breadcrumbs list --- internal/server/breadcrumbs.go | 29 ++++++--- internal/server/handlers.go | 8 ++- internal/server/semantic_handlers.go | 11 +++- templates/pages/page.gohtml | 88 +++++++++++++++++++++------- 4 files changed, 100 insertions(+), 36 deletions(-) diff --git a/internal/server/breadcrumbs.go b/internal/server/breadcrumbs.go index 514fcd8..76ddc47 100644 --- a/internal/server/breadcrumbs.go +++ b/internal/server/breadcrumbs.go @@ -11,12 +11,18 @@ func buildBreadcrumbs( path string, ) []Breadcrumb { - path = cleanSemanticPath(path) + path = + strings.TrimSpace(path) - if path == "/" { + if path == "" || + path == "/" { return nil } + if !strings.HasPrefix(path, "/") { + path = "/" + path + } + parts := strings.Split( strings.Trim(path, "/"), @@ -26,14 +32,21 @@ func buildBreadcrumbs( var out []Breadcrumb current := "" - for _, p := range parts { + for _, part := range parts { - current += "/" + p + if part == "" { + continue + } - out = append(out, Breadcrumb{ - Name: p, - Path: current, - }) + current += "/" + part + + out = append( + out, + Breadcrumb{ + Name: part, + Path: current, + }, + ) } return out diff --git a/internal/server/handlers.go b/internal/server/handlers.go index c72d864..cee161b 100644 --- a/internal/server/handlers.go +++ b/internal/server/handlers.go @@ -82,9 +82,11 @@ func (s *Server) handleHome( ObjectURI: "uuid:" + objectUUID, }, ), - "Title": homePath, - "Path": homePath, - "ObjectUUID": objectUUID, + "IsHome": true, + "Title": homePath, + "Path": homePath, + "Breadcrumbs": buildBreadcrumbs(homePath), + "ObjectUUID": objectUUID, "RenderedHTML": template.HTML( rendered, ), diff --git a/internal/server/semantic_handlers.go b/internal/server/semantic_handlers.go index 678a8aa..5d3c610 100644 --- a/internal/server/semantic_handlers.go +++ b/internal/server/semantic_handlers.go @@ -2,6 +2,7 @@ package server import ( "html/template" + "log" "net/http" "strings" ) @@ -39,6 +40,9 @@ func (s *Server) handleSemanticRoute( return } + bs := buildBreadcrumbs(path) + log.Printf("breadcrumb debug path=%s bs=%#v", path, bs) + rendered := s.expandMacros( latest.Body, @@ -49,9 +53,10 @@ func (s *Server) handleSemanticRoute( w, "page.gohtml", map[string]any{ - "Title": path, - "Path": path, - "ObjectUUID": objectUUID, + "Title": path, + "Path": path, + "Breadcrumbs": buildBreadcrumbs(path), + "ObjectUUID": objectUUID, "NavItems": resolveNavItems( s.getSystemNavItems(), NavContext{ diff --git a/templates/pages/page.gohtml b/templates/pages/page.gohtml index 39c4d67..e74b800 100644 --- a/templates/pages/page.gohtml +++ b/templates/pages/page.gohtml @@ -3,48 +3,56 @@ - - -{{ .Title }} - - - - - +{{ .Name }} + + - +
- -
-
+
-
-{{ .Path }} -
+{{ if ne .Path "/" }} + + + + +{{ end }}
{{ .RenderedHTML }} @@ -56,6 +64,32 @@