docs(ui): canonicalize .md URLs — sidebar now opens when arriving from overview links
Root cause of 'clicked from overview, bold but menus closed': cross-page markdown links point at area/file.md; the handler happily loads .md URLs, but the sidebar keys on the URL path — contains-URL expansion and the active-link styling compare against extension-less nav URLs, so a .md path rendered the page with its menu closed and the current item unhighlighted. (My curl checks had used clean URLs, which is why it worked in testing but not from the overview page.) Fix: ShowDocumentation 301-redirects .md paths to the clean canonical form (query preserved; browsers re-attach fragments), and renderDocPage normalizes the path for nav expansion/grouping as a belt- and-braces. Live-verified: .../get_ratings.md -> 301 -> clean page with both containing menus open and the get_ratings link carrying the active class.
This commit is contained in:
1 parent
73e8cdef4b
commit
a1ac5b1541
1 file changed
+18
-1
@@ -48,7 +48,10 @@ func (h *HTTPHandler) currentUser(c *echo.Context) templates.User {
|
|||||||
|
|
||||||
// renderDocPage renders a document inside the docs layout.
|
// renderDocPage renders a document inside the docs layout.
|
||||||
func (h *HTTPHandler) renderDocPage(c *echo.Context, doc *templates.Document) error {
|
func (h *HTTPHandler) renderDocPage(c *echo.Context, doc *templates.Document) error {
|
||||||
currentPath := c.Request().URL.Path
|
// .md suffixes are canonicalized to clean URLs before rendering, but
|
||||||
|
// normalize here too so the nav expansion + active-link styling can
|
||||||
|
// never see an extension the nav URLs don't carry.
|
||||||
|
currentPath := strings.TrimSuffix(c.Request().URL.Path, ".md")
|
||||||
nav := h.docs.BuildNavigation(currentPath)
|
nav := h.docs.BuildNavigation(currentPath)
|
||||||
|
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
@@ -73,6 +76,20 @@ func (h *HTTPHandler) ShowDocumentation(c *echo.Context) error {
|
|||||||
// Get the document path from URL parameter
|
// Get the document path from URL parameter
|
||||||
docPath := c.Param("*")
|
docPath := c.Param("*")
|
||||||
|
|
||||||
|
// Canonicalize ".md" URLs to the clean form. Markdown links across the
|
||||||
|
// docs tree point at `area/file.md`; the handler loads them fine, but
|
||||||
|
// the sidebar logic keys on the URL path (contains-URL expansion, the
|
||||||
|
// active-link styling) whose nav URLs are extension-less — and a raw
|
||||||
|
// .md path would render the page with its menu closed and the current
|
||||||
|
// item unhighlighted. 301 keeps the browser URL canonical.
|
||||||
|
if strings.HasSuffix(docPath, ".md") {
|
||||||
|
target := strings.TrimSuffix("/docs/"+docPath, ".md")
|
||||||
|
if c.Request().URL.RawQuery != "" {
|
||||||
|
target += "?" + c.Request().URL.RawQuery
|
||||||
|
}
|
||||||
|
return c.Redirect(http.StatusMovedPermanently, target)
|
||||||
|
}
|
||||||
|
|
||||||
// Load the document
|
// Load the document
|
||||||
doc, err := h.docs.LoadDocument(docPath)
|
doc, err := h.docs.LoadDocument(docPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in new issue
Block a user