File tree Expand file tree Collapse file tree 4 files changed +27
-3
lines changed Expand file tree Collapse file tree 4 files changed +27
-3
lines changed Original file line number Diff line number Diff line change
1
+ 'use strict'
2
+
3
+ module . exports = (
4
+ navigation ,
5
+ {
6
+ data : {
7
+ root : { page } ,
8
+ } ,
9
+ }
10
+ ) => {
11
+ traceCurrentPathInternal ( navigation , page . url )
12
+ return navigation
13
+ }
14
+
15
+ function traceCurrentPathInternal ( items , currentPageUrl , path = [ ] ) {
16
+ for ( const item of items ) {
17
+ if ( item . url === currentPageUrl ) {
18
+ for ( const ancestor of path ) ancestor . current = 'path'
19
+ item . current = 'page'
20
+ return true
21
+ }
22
+ if ( item . items && traceCurrentPathInternal ( item . items , currentPageUrl , path . concat ( item ) ) ) return true
23
+ }
24
+ }
Original file line number Diff line number Diff line change 16
16
var currentPageItem = menuPanel . querySelector ( '.is-current-page' )
17
17
var originalPageItem = currentPageItem
18
18
if ( currentPageItem ) {
19
- activateCurrentPath ( currentPageItem )
19
+ // activateCurrentPath(currentPageItem) // enable if not handled by template
20
20
scrollItemToMidpoint ( menuPanel , currentPageItem . querySelector ( '.nav-link' ) )
21
21
} else {
22
22
menuPanel . scrollTop = 0
Original file line number Diff line number Diff line change 5
5
{{ #with @root.page.componentVersion }}
6
6
<h3 class =" title" ><a href =" {{{ relativize ./url }}} " >{{ ./title }} </a ></h3 >
7
7
{{ /with }}
8
- {{> nav-tree navigation =this }}
8
+ {{> nav-tree navigation =( traceCurrentPath this ) }}
9
9
</nav >
10
10
</div >
11
11
{{ /with }}
Original file line number Diff line number Diff line change 1
1
{{ #if navigation.length }}
2
2
<ul class =" nav-list" >
3
3
{{ #each navigation }}
4
- <li class =" nav-item{{ #if ( eq ./url @ root.page.url ) }} is-current-page {{ /if }} " data-depth =" {{ or ../level 0 }} " >
4
+ <li class =" nav-item{{ #with ./current }} is-current-{{{ this }}} is-active {{ /with }} " data-depth =" {{ or ../level 0 }} " >
5
5
{{ #if ./content }}
6
6
{{ #if ./items.length }}
7
7
<button class =" nav-item-toggle" ></button >
You can’t perform that action at this time.
0 commit comments