@@ -187,42 +187,34 @@ function updateProgressBarAndFadeIn() {
187187
188188function createRightSidebar ( ) {
189189 const content = document . getElementsByClassName ( 'content' ) [ 0 ] ;
190- if ( ! content ) return ;
190+ const sidebar = document . getElementById ( 'sidebarContent' ) ;
191+ if ( ! content || ! sidebar ) return ;
191192
192193 const sections = content . getElementsByClassName ( 'section' ) ;
193- if ( ! sections ) return ;
194+ if ( ! sections . length ) return ;
194195
195- const sidebarContent = document . getElementById ( 'sidebarContent' ) ;
196- if ( ! sidebarContent ) return ;
197-
198- // Create fragment for batch updates
196+ // Create fragment for batch updates (better performance)
199197 const fragment = document . createDocumentFragment ( ) ;
200198
201199 for ( const section of sections ) {
202- // Get only direct children and sort them
203- const elements = [
204- ...section . children
205- ] . filter ( el =>
200+ // Get section elements (both cards and expanders)
201+ const elements = [ ...section . children ] . filter ( el =>
206202 ( el . classList . contains ( 'card' ) || el . classList . contains ( 'expander-top' ) ) &&
207203 el . parentNode === section
208204 ) . sort ( ( a , b ) =>
209205 a . compareDocumentPosition ( b ) & Node . DOCUMENT_POSITION_FOLLOWING ? - 1 : 1
210206 ) ;
211207
212- // Process headers within each section
208+ // Process headers within section
213209 section . querySelectorAll ( 'h2' ) . forEach ( header => {
214210 if ( ! header . innerHTML ) return ;
215211
216- const sectionDiv = document . createElement ( 'div' ) ;
212+ const div = document . createElement ( 'div' ) ;
217213
218- // Create header elements
219- const bold = document . createElement ( 'b' ) ;
220- const separator = Object . assign ( document . createElement ( 'a' ) , {
221- href : `#${ section . id } ` ,
222- textContent : header . innerHTML
223- } ) ;
224- bold . appendChild ( separator ) ;
225- sectionDiv . appendChild ( bold ) ;
214+ // Create header link
215+ const b = document . createElement ( 'b' ) ;
216+ b . innerHTML = `<a href="#${ section . id } ">${ header . innerHTML } </a>` ;
217+ div . appendChild ( b ) ;
226218
227219 // Add all elements for this section
228220 elements . forEach ( element => {
@@ -231,17 +223,17 @@ function createRightSidebar() {
231223
232224 if ( ! text ) return ;
233225
234- sectionDiv . appendChild ( Object . assign ( document . createElement ( 'a' ) , {
235- href : `#${ element . id } ` ,
236- textContent : text
237- } ) ) ;
226+ const a = document . createElement ( 'a' ) ;
227+ a . href = `#${ element . id } ` ;
228+ a . textContent = text ;
229+ div . appendChild ( a ) ;
238230 } ) ;
239231
240- fragment . appendChild ( sectionDiv ) ;
232+ fragment . appendChild ( div ) ;
241233 } ) ;
242234 }
243235
244- sidebarContent . appendChild ( fragment ) ;
236+ sidebar . appendChild ( fragment ) ;
245237}
246238
247239function markActivePage ( ) {
0 commit comments