@@ -114,20 +114,40 @@ Alpine.data('countdown', (iso) => ({
114114Livewire . start ( )
115115
116116// Docsearch
117- docsearch ( {
117+ const docsPathMatch = window . location . pathname . match ( / ^ \/ d o c s \/ ( d e s k t o p | m o b i l e ) \/ ( \d + ) / )
118+ const docsearchOptions = {
118119 appId : 'ZNII9QZ8WI' ,
119120 apiKey : '9be495a1aaf367b47c873d30a8e7ccf5' ,
120121 indexName : 'nativephp' ,
121122 insights : true ,
122- container : '#docsearch-desktop' ,
123123 debug : false ,
124- } )
124+ ...( docsPathMatch && {
125+ transformItems ( items ) {
126+ const prefix = `/docs/${ docsPathMatch [ 1 ] } /${ docsPathMatch [ 2 ] } /`
127+ return items . filter ( ( item ) => {
128+ try {
129+ return new URL ( item . url ) . pathname . startsWith ( prefix )
130+ } catch {
131+ return item . url . includes ( prefix )
132+ }
133+ } )
134+ } ,
135+ } ) ,
136+ }
125137
126138docsearch ( {
127- appId : 'ZNII9QZ8WI' ,
128- apiKey : '9be495a1aaf367b47c873d30a8e7ccf5' ,
129- indexName : 'nativephp' ,
130- insights : true ,
131- container : '#docsearch-mobile' ,
132- debug : false ,
139+ ...docsearchOptions ,
140+ container : '#docsearch-desktop' ,
133141} )
142+
143+ // Mirror the desktop DocSearch button into the mobile container so that
144+ // pressing Cmd+K only registers one handler (avoiding duplicate modals).
145+ const mobileContainer = document . getElementById ( 'docsearch-mobile' )
146+ if ( mobileContainer ) {
147+ const desktopButton = document . querySelector ( '#docsearch-desktop .DocSearch-Button' )
148+ if ( desktopButton ) {
149+ const mobileButton = desktopButton . cloneNode ( true )
150+ mobileContainer . appendChild ( mobileButton )
151+ mobileButton . addEventListener ( 'click' , ( ) => desktopButton . click ( ) )
152+ }
153+ }
0 commit comments