|
| 1 | +--- |
| 2 | +import Default from '@astrojs/starlight/components/Search.astro'; |
| 3 | +--- |
| 4 | +<Default /> |
| 5 | + |
| 6 | +<script> |
| 7 | + // Command-palette empty state: inject quick links + a shortcut footer into the |
| 8 | + // Pagefind modal once it mounts. terminal.css shows it only while the query is |
| 9 | + // empty (the results drawer carries .pagefind-ui__hidden then). |
| 10 | + const PANEL = ` |
| 11 | + <div class="echo-search-empty"> |
| 12 | + <div class="ess-group"> |
| 13 | + <div class="ess-label">Start here</div> |
| 14 | + <a class="ess-link" href="/guide/quickstart/"><i aria-hidden="true" class="ph ph-rocket-launch"></i> Quickstart <span class="ess-sec">Guide</span></a> |
| 15 | + <a class="ess-link" href="/guide/routing/"><i aria-hidden="true" class="ph ph-signpost"></i> Routing <span class="ess-sec">Guide</span></a> |
| 16 | + <a class="ess-link" href="/guide/binding/"><i aria-hidden="true" class="ph ph-brackets-curly"></i> Binding <span class="ess-sec">Guide</span></a> |
| 17 | + </div> |
| 18 | + <div class="ess-group"> |
| 19 | + <div class="ess-label">Popular</div> |
| 20 | + <a class="ess-link" href="/middleware/jwt/"><i aria-hidden="true" class="ph ph-lock-key"></i> JWT <span class="ess-sec">Middleware</span></a> |
| 21 | + <a class="ess-link" href="/middleware/cors/"><i aria-hidden="true" class="ph ph-globe"></i> CORS <span class="ess-sec">Middleware</span></a> |
| 22 | + <a class="ess-link" href="/cookbook/hello-world/"><i aria-hidden="true" class="ph ph-cube"></i> Hello World <span class="ess-sec">Cookbook</span></a> |
| 23 | + </div> |
| 24 | + <div class="ess-foot"> |
| 25 | + <span><kbd>↵</kbd>open</span><span><kbd>↑</kbd><kbd>↓</kbd>navigate</span><span><kbd>esc</kbd>close</span> |
| 26 | + </div> |
| 27 | + </div>`; |
| 28 | + |
| 29 | + function inject() { |
| 30 | + const ui = document.querySelector('.pagefind-ui'); |
| 31 | + if (!ui || ui.querySelector('.echo-search-empty')) return !!ui; |
| 32 | + const form = ui.querySelector('.pagefind-ui__form'); |
| 33 | + if (!form) return false; |
| 34 | + form.insertAdjacentHTML('afterend', PANEL); |
| 35 | + return true; |
| 36 | + } |
| 37 | + |
| 38 | + // Pagefind mounts lazily when the dialog first opens — watch for it, then stop. |
| 39 | + if (!inject()) { |
| 40 | + const obs = new MutationObserver(() => { if (inject()) obs.disconnect(); }); |
| 41 | + obs.observe(document.body, { childList: true, subtree: true }); |
| 42 | + // Bound the observer: if Pagefind never mounts (disabled in dev, or the |
| 43 | + // Starlight markup changed on upgrade), stop watching so it can't run for |
| 44 | + // the page's lifetime. Losing the launchpad is harmless; search still works. |
| 45 | + setTimeout(() => { |
| 46 | + obs.disconnect(); |
| 47 | + if (import.meta.env.DEV && !document.querySelector('.echo-search-empty')) { |
| 48 | + console.warn('[search] empty-state panel not injected — .pagefind-ui selectors may have changed'); |
| 49 | + } |
| 50 | + }, 10000); |
| 51 | + } |
| 52 | +</script> |
0 commit comments