@@ -187,42 +187,34 @@ function updateProgressBarAndFadeIn() {
187
187
188
188
function createRightSidebar ( ) {
189
189
const content = document . getElementsByClassName ( 'content' ) [ 0 ] ;
190
- if ( ! content ) return ;
190
+ const sidebar = document . getElementById ( 'sidebarContent' ) ;
191
+ if ( ! content || ! sidebar ) return ;
191
192
192
193
const sections = content . getElementsByClassName ( 'section' ) ;
193
- if ( ! sections ) return ;
194
+ if ( ! sections . length ) return ;
194
195
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)
199
197
const fragment = document . createDocumentFragment ( ) ;
200
198
201
199
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 =>
206
202
( el . classList . contains ( 'card' ) || el . classList . contains ( 'expander-top' ) ) &&
207
203
el . parentNode === section
208
204
) . sort ( ( a , b ) =>
209
205
a . compareDocumentPosition ( b ) & Node . DOCUMENT_POSITION_FOLLOWING ? - 1 : 1
210
206
) ;
211
207
212
- // Process headers within each section
208
+ // Process headers within section
213
209
section . querySelectorAll ( 'h2' ) . forEach ( header => {
214
210
if ( ! header . innerHTML ) return ;
215
211
216
- const sectionDiv = document . createElement ( 'div' ) ;
212
+ const div = document . createElement ( 'div' ) ;
217
213
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 ) ;
226
218
227
219
// Add all elements for this section
228
220
elements . forEach ( element => {
@@ -231,17 +223,17 @@ function createRightSidebar() {
231
223
232
224
if ( ! text ) return ;
233
225
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 ) ;
238
230
} ) ;
239
231
240
- fragment . appendChild ( sectionDiv ) ;
232
+ fragment . appendChild ( div ) ;
241
233
} ) ;
242
234
}
243
235
244
- sidebarContent . appendChild ( fragment ) ;
236
+ sidebar . appendChild ( fragment ) ;
245
237
}
246
238
247
239
function markActivePage ( ) {
0 commit comments