Skip to content

Commit f7d6513

Browse files
committed
Fix(ui):Fixed the docs whatever opened componenent section to be highlighted
Signed-off-by: Akshat Sinha <[email protected]>
1 parent d9448b1 commit f7d6513

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

assets/scss/_sidebar-tree.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181

8282
&.active {
8383
font-weight: $font-weight-bold;
84+
color: $secondary;
8485
}
8586
}
8687

layouts/partials/head.html

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,12 @@
6464
{{ end -}}
6565
*/ -}}
6666

67-
67+
<script>
68+
document.addEventListener('DOMContentLoaded',()=>{const n=s=>(s||'').replace(/\/+$/,''); const cur=n(location.pathname); let b=null,l=-1;
69+
document.querySelectorAll('.td-sidebar-nav a[href]').forEach(a=>{const p=n(new URL(a.getAttribute('href'),location).pathname); if(p&&(cur===p||cur.startsWith(p+'/'))&&p.length>l){b=a;l=p.length}});
70+
if(!b)return; b.classList.add('active');
71+
for(let e=b.parentElement;e&&!e.classList.contains('td-sidebar-nav');e=e.parentElement){ if(e.tagName==='LI'){const pa=e.querySelector(':scope > a'); if(pa)pa.classList.add('active'); const ul=e.querySelector(':scope > ul'); if(ul)ul.classList.add('show')}}});
72+
</script>
6873

6974
{{ define "algolia/head" -}}
7075

@@ -79,4 +84,4 @@
7984
For details, see https://www.docsy.dev/docs/adding-content/search/#algolia-docsearch.` -}}
8085
{{ end -}}
8186

82-
{{ end -}}
87+
{{ end -}}

0 commit comments

Comments
 (0)