File tree Expand file tree Collapse file tree
_javascript/modules/layouts Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -130,6 +130,32 @@ async function navigate(url, pushState = true) {
130130 panel . innerHTML = newPanel . innerHTML ;
131131 }
132132
133+ // Replace tail content (comments etc.) but preserve footer
134+ const tail = container . querySelector ( '#tail-wrapper' ) ;
135+ const newTail = newContainer . querySelector ( '#tail-wrapper' ) ;
136+ if ( tail && newTail ) {
137+ const footer = tail . querySelector ( 'footer' ) ;
138+ /* Remove everything except footer */
139+ [ ...tail . childNodes ]
140+ . filter ( ( n ) => n . nodeName !== 'FOOTER' )
141+ . forEach ( ( n ) => n . remove ( ) ) ;
142+ /* Insert new content before footer */
143+ [ ...newTail . childNodes ]
144+ . filter ( ( n ) => n . nodeName !== 'FOOTER' )
145+ . forEach ( ( n ) => {
146+ const node = n . cloneNode ( true ) ;
147+ tail . insertBefore ( node , footer ) ;
148+ } ) ;
149+ /* Re-execute scripts (needed for Giscus) */
150+ tail . querySelectorAll ( 'script' ) . forEach ( ( old ) => {
151+ const s = document . createElement ( 'script' ) ;
152+ if ( old . src ) s . src = old . src ;
153+ else s . textContent = old . textContent ;
154+ [ ...old . attributes ] . forEach ( ( a ) => s . setAttribute ( a . name , a . value ) ) ;
155+ old . replaceWith ( s ) ;
156+ } ) ;
157+ }
158+
133159 // Update title
134160 document . title = doc . title ;
135161
You can’t perform that action at this time.
0 commit comments