Odoc plugins for jon.recoil.org
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix sidebar not appearing on SPA navigation to reference pages

The SPA navigateTo() only swapped .odoc-content, but the sidebar <nav>
element is only server-rendered on reference/ pages. When navigating
from home/blog to reference/, the sidebar container didn't exist in the
DOM so initSidebar() had nothing to populate.

Now navigateTo() creates the sidebar element and fetches sidebar.json
when entering reference/, and removes it when leaving.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

+26 -1
+26 -1
src/odoc_jons_plugins_js.ml
··· 256 256 history.pushState({ url: url }, '', ROOT_URL + url); 257 257 } 258 258 259 - updateSidebarActive(); 259 + // Handle sidebar: create/remove based on whether we're in reference/ 260 + var isRef = url.indexOf('reference/') === 0; 261 + var sidebar = document.getElementById('sidebar-content'); 262 + var main = document.querySelector('.jon-shell-main'); 263 + if (isRef && !sidebar && main) { 264 + sidebar = document.createElement('nav'); 265 + sidebar.className = 'jon-shell-sidebar odoc-global-toc'; 266 + sidebar.id = 'sidebar-content'; 267 + main.insertBefore(sidebar, main.firstChild); 268 + // Fetch and init sidebar data 269 + fetch(ROOT_URL + 'sidebar.json') 270 + .then(function(r) { 271 + if (!r.ok) throw new Error('sidebar.json: ' + r.status); 272 + return r.json(); 273 + }) 274 + .then(function(data) { initSidebar(data); }) 275 + .catch(function(e) { console.warn('Failed to load sidebar:', e); }); 276 + } else if (!isRef && sidebar) { 277 + sidebar.remove(); 278 + } else { 279 + updateSidebarActive(); 280 + } 281 + 282 + // Show/hide sidebar toggle button 283 + var toggleBtn = document.querySelector('.jon-shell-sidebar-toggle'); 284 + if (toggleBtn) toggleBtn.style.display = isRef ? '' : 'none'; 260 285 261 286 // Scroll handling 262 287 var hash = url.indexOf('#') >= 0 ? '#' + url.split('#')[1] : '';