fix(docs): folder-index pages expand the sidebar and highlight — same rule for every page
The filter manual is the docs tree's first FOLDER-index page: it serves at /docs/user/filters while its nav entry carries /index (/docs/user/filters/index). The sidebar's two checks — group expansion (containsURL) and active-link styling (docsNavClass) — compared URLs EXACTLY, so the folder URL matched neither: no submenu expansion, no highlight (2026-11-01 user report: "the left sidebar should open to the submenu and highlight the page"). Fix is structural, not per-page: both checks normalize folder-index URLs (a trailing /index is the same page as its directory), so EVERY folder-index page — current and future — expands and highlights like a file page. No per-page registration exists anywhere in the docs system to redo: the sidebar derives from the docs tree, and this was the one URL shape its equality rule missed. Pins: navigation (section + group expand for the folder URL, group present) and docsNavClass (folder URL highlights the Overview item, normalization symmetric, file pages keep their highlight, no cross-highlighting).
This commit is contained in:
1 parent
a4dc03984c
commit
0d613ba0e3
4 files changed
+82
-4
No files matched your search
@@ -321,10 +321,23 @@ func (h *DocsHandler) BuildNavigation(currentPath string) *templates.Navigation
|
||||
return nav
|
||||
}
|
||||
|
||||
// containsURL reports whether currentPath is one of the given doc URLs.
|
||||
// normalizeDocURL — folder-index pages SERVE at their directory URL
|
||||
// (/docs/user/filters) while their nav entry carries the /index suffix
|
||||
// (/docs/user/filters/index): same page, two spellings. Both sidebar
|
||||
// checks (expansion + highlight) compare normalized forms, so folder
|
||||
// pages expand and highlight like file pages — no per-page special
|
||||
// cases (2026-11-01, the filter manual's folder).
|
||||
func normalizeDocURL(u string) string {
|
||||
u = strings.TrimRight(u, "/")
|
||||
return strings.TrimSuffix(u, "/index")
|
||||
}
|
||||
|
||||
// containsURL reports whether currentPath is one of the given doc URLs
|
||||
// (folder-index URLs normalized — see normalizeDocURL).
|
||||
func containsURL(currentPath string, urls []string) bool {
|
||||
current := normalizeDocURL(currentPath)
|
||||
for _, u := range urls {
|
||||
if currentPath == u {
|
||||
if current == normalizeDocURL(u) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"bookhoard/templates"
|
||||
)
|
||||
|
||||
func TestPlaceDoc(t *testing.T) {
|
||||
@@ -205,3 +207,41 @@ func TestBuildNavigationNothingCurrent(t *testing.T) {
|
||||
t.Errorf("expected zero sections open when nothing matches (docs home / 404 renders fully closed), got %d", open)
|
||||
}
|
||||
}
|
||||
|
||||
// TestBuildNavigationFolderIndex (2026-11-01): folder-index pages serve
|
||||
// at their directory URL (/docs/user/filters) while their nav entries
|
||||
// carry /index (/docs/user/filters/index) — the sidebar must EXPAND the
|
||||
// containing section/group and HIGHLIGHT the index item for the folder
|
||||
// URL, exactly like a file page. The filter manual's folder is the
|
||||
// first page of this shape.
|
||||
func TestBuildNavigationFolderIndex(t *testing.T) {
|
||||
// The REAL docs tree: the Filters group only exists because the
|
||||
// filter manual (guide/cookbook/fields) lives in user/filters/.
|
||||
handler := NewDocsHandler("../../docs")
|
||||
nav := handler.BuildNavigation("/docs/user/filters")
|
||||
|
||||
var userGuide *templates.NavSection
|
||||
for i := range nav.Sections {
|
||||
if nav.Sections[i].Title == "User Guide" {
|
||||
userGuide = &nav.Sections[i]
|
||||
}
|
||||
}
|
||||
if userGuide == nil {
|
||||
t.Fatal("User Guide section missing")
|
||||
}
|
||||
if userGuide.Collapsed {
|
||||
t.Error("User Guide section must expand for /docs/user/filters")
|
||||
}
|
||||
var filters *templates.NavGroup
|
||||
for i := range userGuide.Groups {
|
||||
if userGuide.Groups[i].Title == "Filters" {
|
||||
filters = &userGuide.Groups[i]
|
||||
}
|
||||
}
|
||||
if filters == nil {
|
||||
t.Fatal("Filters group missing from User Guide")
|
||||
}
|
||||
if filters.Collapsed {
|
||||
t.Error("Filters group must expand for its folder URL")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user