|
19 | 19 |
|
20 | 20 | /* |
21 | 21 | * Comet docs UX enhancements layered on top of pydata_sphinx_theme: |
| 22 | + * - "Home" tab injected at the start of the top navbar (toctree can't |
| 23 | + * self-reference, so the landing page link lives here) |
22 | 24 | * - Click-to-toggle expand/collapse arrows on sidebar nav groups |
23 | 25 | * - In-sidebar search filter with character highlighting (replaces the |
24 | 26 | * default Sphinx redirect-to-/search.html flow) |
|
172 | 174 | }); |
173 | 175 | } |
174 | 176 |
|
| 177 | + // ── Inject "Home" link into the top navbar ───────────────────────── |
| 178 | + // The toctree can't self-reference, so we add the Home tab via JS. |
| 179 | + // It's prepended to the desktop nav AND the mobile drawer. The link |
| 180 | + // is computed from the navbar logo's href so it stays correct at any |
| 181 | + // page depth. |
| 182 | + function initHomeNavLink() { |
| 183 | + var logo = document.querySelector('a.navbar-brand'); |
| 184 | + var homeHref = logo ? logo.getAttribute('href') : null; |
| 185 | + if (!homeHref) return; |
| 186 | + |
| 187 | + var isHomePage = !!document.querySelector('.comet-hero'); |
| 188 | + |
| 189 | + document |
| 190 | + .querySelectorAll('.bd-navbar-elements.navbar-nav') |
| 191 | + .forEach(function (nav) { |
| 192 | + if (nav.querySelector('.comet-home-nav-item')) return; |
| 193 | + |
| 194 | + var li = document.createElement('li'); |
| 195 | + li.className = 'nav-item comet-home-nav-item'; |
| 196 | + if (isHomePage) li.classList.add('active', 'current'); |
| 197 | + |
| 198 | + var a = document.createElement('a'); |
| 199 | + a.className = 'nav-link nav-internal'; |
| 200 | + a.setAttribute('href', homeHref); |
| 201 | + if (isHomePage) a.setAttribute('aria-current', 'page'); |
| 202 | + a.textContent = 'Home'; |
| 203 | + |
| 204 | + li.appendChild(a); |
| 205 | + nav.insertBefore(li, nav.firstChild); |
| 206 | + }); |
| 207 | + } |
| 208 | + |
175 | 209 | // ── Breadcrumb trim ──────────────────────────────────────────────── |
176 | 210 | // "Comet 0.16.0-SNAPSHOT User Guide" reads as noise in a breadcrumb |
177 | 211 | // when the section is already shown in the top nav. Trim to "0.16.0- |
|
204 | 238 | } |
205 | 239 |
|
206 | 240 | function bootstrap() { |
| 241 | + initHomeNavLink(); |
207 | 242 | initSidebarToggle(); |
208 | 243 | initSidebarSearch(); |
209 | 244 | initSecondaryTocVisibility(); |
|
0 commit comments