@@ -617,22 +617,28 @@ export async function websiteSearchIncludeInHeader(
617617 }
618618 } ) ;
619619
620- const searchOptionsJson = JSON . stringify ( options , null , 2 ) ;
621- const searchOptionsScript =
622- `<script id="quarto-search-options" type="application/json">${ searchOptionsJson } </script>` ;
623- const includes = [ searchOptionsScript ] ;
620+ const includes : string [ ] = [ ] ;
624621
622+ // Process all Algolia configuration and scripts
625623 if ( options [ kAlgolia ] ) {
626624 includes . push ( kAlogioSearchApiScript ) ;
627- if ( options [ kAlgolia ] ?. [ kAnalyticsEvents ] ) {
625+ if ( options [ kAlgolia ] [ kAnalyticsEvents ] ) {
628626 const cookieConsent = cookieConsentEnabled ( project ) ;
629- // Pass cookie consent status to JavaScript for Algolia Insights configuration
627+ // Set cookie consent flag for JavaScript configuration
630628 options [ kAlgolia ] [ kCookieConsentEnabled ] = cookieConsent ;
629+ // Add Algolia Insights scripts with proper consent handling
631630 includes . push ( algoliaSearchInsightsScript ( cookieConsent ) ) ;
632631 includes . push ( autocompleteInsightsPluginScript ( cookieConsent ) ) ;
633632 }
634633 }
635634
635+ // Serialize search options to JSON after all modifications
636+ const searchOptionsJson = JSON . stringify ( options , null , 2 ) ;
637+ const searchOptionsScript =
638+ `<script id="quarto-search-options" type="application/json">${ searchOptionsJson } </script>` ;
639+ // Prepend search options script to beginning of includes
640+ includes . unshift ( searchOptionsScript ) ;
641+
636642 Deno . writeTextFileSync ( websiteSearchScript , includes . join ( "\n" ) ) ;
637643 return websiteSearchScript ;
638644}
0 commit comments