@@ -12,14 +12,21 @@ document.addEventListener("astro:page-load", () => {
12
12
function doToc ( toc : HTMLElement ) {
13
13
const titles = new Map ( ) ;
14
14
15
- Array . from ( toc . children ) . forEach ( node => {
15
+ // ugly hack :^)
16
+ // reverse children, so priority is for the last visible TOC element
17
+ // but push first element so it takes priority over the 2nd element
18
+ const toc_children = Array . from ( toc . children ) ;
19
+ // @ts -expect-error The TOC will always have >1 elements
20
+ toc_children . push ( toc_children [ 0 ] )
21
+ toc_children . reverse ( ) ;
22
+
23
+ toc_children . forEach ( node => {
16
24
if ( ! ( node instanceof HTMLElement ) ) {
17
25
return ;
18
26
}
19
27
20
28
const slug = node . dataset . slug ;
21
- if ( slug === undefined ) { return ; }
22
-
29
+ if ( slug === undefined ) { return ; }
23
30
24
31
titles . set ( slug , false ) ;
25
32
} )
@@ -63,22 +70,25 @@ function doToc(toc: HTMLElement) {
63
70
}
64
71
65
72
const slug = entry . target . dataset . headingId ;
73
+ // console.log(slug, entry.isIntersecting, entry.intersectionRatio);
74
+
66
75
if ( slug === undefined ) {
67
76
return ;
68
77
}
69
78
70
79
titles . set ( slug , entry . isIntersecting ) ;
80
+ // console.log(titles);
71
81
72
82
73
83
updateTitles ( ) ;
74
84
} )
75
85
} , {
76
- threshold : 0.9 ,
86
+ threshold : [ 0 , 0.25 , 0.5 , 0.75 , 1 ] ,
77
87
} ) ;
78
88
79
89
titles . forEach ( ( _ , slug ) => {
80
90
const section = document . querySelectorAll ( `[data-heading-id="${ slug } "]` ) [ 0 ] ;
81
- if ( section === undefined ) { return ; }
91
+ if ( section === undefined ) { return ; }
82
92
83
93
observer . observe ( section ) ;
84
94
} ) ;
0 commit comments