diff --git a/resources/js/app.js b/resources/js/app.js
index 2923c60f..a1a7363b 100644
--- a/resources/js/app.js
+++ b/resources/js/app.js
@@ -114,20 +114,40 @@ Alpine.data('countdown', (iso) => ({
Livewire.start()
// Docsearch
-docsearch({
+const docsPathMatch = window.location.pathname.match(/^\/docs\/(desktop|mobile)\/(\d+)/)
+const docsearchOptions = {
appId: 'ZNII9QZ8WI',
apiKey: '9be495a1aaf367b47c873d30a8e7ccf5',
indexName: 'nativephp',
insights: true,
- container: '#docsearch-desktop',
debug: false,
-})
+ ...(docsPathMatch && {
+ transformItems(items) {
+ const prefix = `/docs/${docsPathMatch[1]}/${docsPathMatch[2]}/`
+ return items.filter((item) => {
+ try {
+ return new URL(item.url).pathname.startsWith(prefix)
+ } catch {
+ return item.url.includes(prefix)
+ }
+ })
+ },
+ }),
+}
docsearch({
- appId: 'ZNII9QZ8WI',
- apiKey: '9be495a1aaf367b47c873d30a8e7ccf5',
- indexName: 'nativephp',
- insights: true,
- container: '#docsearch-mobile',
- debug: false,
+ ...docsearchOptions,
+ container: '#docsearch-desktop',
})
+
+// Mirror the desktop DocSearch button into the mobile container so that
+// pressing Cmd+K only registers one handler (avoiding duplicate modals).
+const mobileContainer = document.getElementById('docsearch-mobile')
+if (mobileContainer) {
+ const desktopButton = document.querySelector('#docsearch-desktop .DocSearch-Button')
+ if (desktopButton) {
+ const mobileButton = desktopButton.cloneNode(true)
+ mobileContainer.appendChild(mobileButton)
+ mobileButton.addEventListener('click', () => desktopButton.click())
+ }
+}
diff --git a/resources/views/docs/index.blade.php b/resources/views/docs/index.blade.php
index 71d16f22..930fe255 100644
--- a/resources/views/docs/index.blade.php
+++ b/resources/views/docs/index.blade.php
@@ -1,3 +1,8 @@
+@push('head')
+
+
+@endpush
+
{!! $navigation !!}
diff --git a/tests/Feature/DocsSearchMetaTagsTest.php b/tests/Feature/DocsSearchMetaTagsTest.php
new file mode 100644
index 00000000..41d77f7b
--- /dev/null
+++ b/tests/Feature/DocsSearchMetaTagsTest.php
@@ -0,0 +1,45 @@
+withoutVite()
+ ->get('/docs/mobile/3/getting-started/introduction')
+ ->assertStatus(200)
+ ->assertSee('', false)
+ ->assertSee('', false);
+ }
+
+ #[Test]
+ public function docs_page_includes_docsearch_platform_and_version_meta_tags_for_desktop(): void
+ {
+ $this
+ ->withoutVite()
+ ->get('/docs/desktop/2/getting-started/introduction')
+ ->assertStatus(200)
+ ->assertSee('', false)
+ ->assertSee('', false);
+ }
+
+ #[Test]
+ public function non_docs_page_does_not_include_docsearch_meta_tags(): void
+ {
+ $this
+ ->withoutVite()
+ ->get('/')
+ ->assertStatus(200)
+ ->assertDontSee('docsearch:platform', false)
+ ->assertDontSee('docsearch:version', false);
+ }
+}