@@ -4,14 +4,33 @@ let fuse = null;
44
55// Fetch and cache recipe data
66async function loadRecipeData ( ) {
7- if ( recipeData ) return recipeData ;
7+ if ( recipeData ) {
8+ console . log ( '[loadRecipeData] Using cached recipe data' ) ;
9+ return recipeData ;
10+ }
811
12+ console . log ( '[loadRecipeData] Fetching /index.json...' ) ;
913 try {
1014 const response = await fetch ( '/index.json' ) ;
15+ console . log ( '[loadRecipeData] Fetch response status:' , response . status ) ;
16+
17+ if ( ! response . ok ) {
18+ throw new Error ( `HTTP error! status: ${ response . status } ` ) ;
19+ }
20+
1121 recipeData = await response . json ( ) ;
22+ console . log ( '[loadRecipeData] Recipe data loaded:' , Object . keys ( recipeData ) . length , 'recipes' ) ;
23+
24+ // Check if Fuse.js is available
25+ if ( typeof Fuse === 'undefined' ) {
26+ console . error ( '[loadRecipeData] Fuse.js is not loaded!' ) ;
27+ throw new Error ( 'Fuse.js library not available' ) ;
28+ }
29+ console . log ( '[loadRecipeData] Fuse.js is available' ) ;
1230
1331 // Initialize Fuse.js for search
1432 const recipesArray = Object . values ( recipeData ) ;
33+ console . log ( '[loadRecipeData] Initializing Fuse with' , recipesArray . length , 'recipes' ) ;
1534 fuse = new Fuse ( recipesArray , {
1635 keys : [
1736 { name : 'title' , weight : 3 } ,
@@ -23,10 +42,11 @@ async function loadRecipeData() {
2342 includeScore : true ,
2443 ignoreLocation : true
2544 } ) ;
45+ console . log ( '[loadRecipeData] Fuse initialized successfully' ) ;
2646
2747 return recipeData ;
2848 } catch ( error ) {
29- console . error ( 'Failed to load recipe data:' , error ) ;
49+ console . error ( '[loadRecipeData] Failed to load recipe data:' , error ) ;
3050 return null ;
3151 }
3252}
@@ -91,29 +111,42 @@ window.pickRandomRecipe = async function() {
91111
92112// Perform search and display results
93113async function performSearch ( ) {
114+ console . log ( '[performSearch] Starting search' ) ;
94115 const urlParams = new URLSearchParams ( window . location . search ) ;
95116 const query = urlParams . get ( 'q' ) ;
96117 const searchQueryInput = document . getElementById ( 'search-query' ) ;
97118 const resultsContainer = document . getElementById ( 'search-results' ) ;
98119 const statsContainer = document . getElementById ( 'search-stats' ) ;
99120
100- if ( ! query || ! resultsContainer ) return ;
121+ console . log ( '[performSearch] Query:' , query ) ;
122+ console . log ( '[performSearch] Results container exists:' , ! ! resultsContainer ) ;
123+
124+ if ( ! query || ! resultsContainer ) {
125+ console . log ( '[performSearch] Missing query or results container, exiting' ) ;
126+ return ;
127+ }
101128
102129 // Set the search input value
103130 if ( searchQueryInput ) {
104131 searchQueryInput . value = query ;
105132 }
106133
107134 // Load recipe data and ensure Fuse is initialized
135+ console . log ( '[performSearch] Loading recipe data...' ) ;
108136 await loadRecipeData ( ) ;
109137
138+ console . log ( '[performSearch] Fuse initialized:' , ! ! fuse ) ;
139+
110140 if ( ! fuse ) {
141+ console . error ( '[performSearch] Fuse not initialized, showing error message' ) ;
111142 resultsContainer . innerHTML = '<p class="text-muted-foreground italic col-span-2">Failed to load search index</p>' ;
112143 return ;
113144 }
114145
115146 // Perform search
147+ console . log ( '[performSearch] Performing search for:' , query ) ;
116148 const results = fuse . search ( query ) ;
149+ console . log ( '[performSearch] Search results count:' , results . length ) ;
117150
118151 // Display stats
119152 if ( statsContainer ) {
0 commit comments