@@ -194,7 +194,6 @@ <h2 class="text-delta">Table of contents</h2>
194194
195195 < script src ="/assets/js/clipboard.min.js "> </ script >
196196 < script >
197- // Add copy buttons to code blocks
198197 document . addEventListener ( 'DOMContentLoaded' , function ( ) {
199198 document . querySelectorAll ( '.highlight' ) . forEach ( function ( block ) {
200199 var btn = document . createElement ( 'button' ) ;
@@ -211,6 +210,46 @@ <h2 class="text-delta">Table of contents</h2>
211210 block . appendChild ( btn ) ;
212211 } ) ;
213212 } ) ;
213+
214+ document . addEventListener ( 'DOMContentLoaded' , function ( ) {
215+ const tocLinks = document . querySelectorAll ( '.toc-sidebar .toc-link' ) ;
216+ if ( tocLinks . length === 0 ) return ;
217+
218+ const headingIds = Array . from ( tocLinks ) . map ( link => {
219+ const href = link . getAttribute ( 'href' ) ;
220+ return href ? href . substring ( 1 ) : null ;
221+ } ) . filter ( Boolean ) ;
222+
223+ const headings = headingIds . map ( id => document . getElementById ( id ) ) . filter ( Boolean ) ;
224+ if ( headings . length === 0 ) return ;
225+
226+ function updateActiveSection ( ) {
227+ const scrollPos = window . scrollY + 100 ;
228+
229+ let currentSection = null ;
230+
231+ headings . forEach ( function ( heading ) {
232+ if ( heading . offsetTop <= scrollPos ) {
233+ currentSection = heading . id ;
234+ }
235+ } ) ;
236+
237+ tocLinks . forEach ( function ( link ) {
238+ link . classList . remove ( 'toc-active' ) ;
239+ } ) ;
240+
241+ if ( currentSection ) {
242+ const activeLink = document . querySelector ( '.toc-sidebar .toc-link[href="#' + currentSection + '"]' ) ;
243+ if ( activeLink ) {
244+ activeLink . classList . add ( 'toc-active' ) ;
245+ }
246+ }
247+ }
248+
249+ window . addEventListener ( 'scroll' , updateActiveSection ) ;
250+
251+ updateActiveSection ( ) ;
252+ } ) ;
214253 </ script >
215254</ body >
216255</ html >
0 commit comments