diff --git a/templates/docs.templ b/templates/docs.templ index a3360a71..64c7bd92 100644 --- a/templates/docs.templ +++ b/templates/docs.templ @@ -23,7 +23,7 @@ templ DocsLayout(nav Navigation, doc Document, user User, currentPath string) { - + @DocsTopbar(user) diff --git a/templates/docs_templ.go b/templates/docs_templ.go index b3fbef86..062da2b3 100644 --- a/templates/docs_templ.go +++ b/templates/docs_templ.go @@ -71,7 +71,7 @@ func DocsLayout(nav Navigation, doc Document, user User, currentPath string) tem if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "( + `a[href="${location.pathname}"], a[href="${location.pathname.replace(/\.md$/, "")}"]`, + ); + if (!active) return; + + const sb = sidebar.getBoundingClientRect(); + const ar = active.getBoundingClientRect(); + if (ar.top >= sb.top && ar.bottom <= sb.bottom) return; // already visible + + if (ar.top < sb.top) { + sidebar.scrollTop += ar.top - sb.top; + } else { + sidebar.scrollTop += ar.bottom - sb.bottom; + } +} + let docsSearchTimeout: ReturnType | null = null; let docsSearchAbort: AbortController | null = null; @@ -126,4 +153,5 @@ Alpine.data("docs", () => ({ toggleCollapsible, initializeSearch: initializeDocsSearch, initializeCodeCopyButtons, + scrollSidebarToActive, }));