Skip to content

Commit 36d6abb

Browse files
committed
remove debug console log
1 parent 46e6eac commit 36d6abb

File tree

1 file changed

+10
-48
lines changed

1 file changed

+10
-48
lines changed

search.js

Lines changed: 10 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
1-
//todo
2-
// [x] inject search bar
3-
// [x] create search + results modal
4-
// [x] handle responsive case
5-
// [] handle light/dark mode
6-
71
const MEILISEARCH_HOST = 'https://edge.meilisearch.com/'
82
const MEILISEARCH_API_KEY = '776dc6a11c118bd1640c3a9ff9679f920bc384238534fc4861fcde0152e7fd68'; // Public search-only API key
93
const MEILISEARCH_INDEX = 'mintlify-staging';
104

115
function initializeMeilisearchIntegration() {
126
// Add a check at the start of the function to prevent multiple initializations
137
if (document.getElementById('meilisearch-bar-container')) {
14-
console.log('Search bar already exists, skipping initialization');
158
return;
169
}
1710

18-
console.log('Meilisearch integration initializing');
19-
2011
// Modify the responsive visibility handler
2112
const handleResponsiveVisibility = () => {
2213
// Check for both possible IDs
@@ -29,7 +20,6 @@ function initializeMeilisearchIntegration() {
2920
const isMobileView = window.innerWidth < 1024;
3021

3122
if (isMobileView) {
32-
console.log('hide search bar container')
3323
// Hide our search bar
3424
searchBarContainer.style.display = 'none';
3525

@@ -41,7 +31,6 @@ function initializeMeilisearchIntegration() {
4131
originalMobileSearchButton.style.display = 'flex';
4232
}
4333
} else {
44-
console.log('display search bar container')
4534
// Show our search bar
4635
searchBarContainer.style.display = 'block';
4736

@@ -57,31 +46,23 @@ function initializeMeilisearchIntegration() {
5746

5847
// ========= Step 1: Create and inject the visible search bar in the header =========
5948
const initSearchBar = () => {
60-
console.log('Initializing search bar');
6149

6250
// When finding the original search button, also look for mobile version icon
6351
const originalSearchButton = document.getElementById('search-bar-entry');
6452
const originalMobileSearchButton = document.getElementById('search-bar-entry-mobile');
6553

66-
if (!originalSearchButton && !originalMobileSearchButton) {
67-
console.log('Neither desktop nor mobile search buttons found');
68-
} else {
69-
console.log('Found search button(s)');
70-
}
71-
7254
// Find the header where we'll add our search input
7355
const header = document.querySelector('header');
74-
if (!header) {
75-
console.log('Header not found, cannot add search bar');
56+
if (!header) { //header not found, cannot add search bar
7657
return;
7758
}
7859

7960
// Log header properties to help with debugging
80-
console.log('Header found, dimensions:', {
81-
width: header.offsetWidth,
82-
height: header.offsetHeight,
83-
position: window.getComputedStyle(header).position
84-
});
61+
// console.log('Header found, dimensions:', {
62+
// width: header.offsetWidth,
63+
// height: header.offsetHeight,
64+
// position: window.getComputedStyle(header).position
65+
// });
8566

8667
// Try to find a proper container within the header for the search
8768
let headerContainer = null;
@@ -90,7 +71,6 @@ function initializeMeilisearchIntegration() {
9071
const navElement = header.querySelector('nav');
9172
if (navElement) {
9273
headerContainer = navElement;
93-
console.log('Found nav element in header');
9474
}
9575
// Option 2: Look for a flex container in the header
9676
else {
@@ -104,11 +84,9 @@ function initializeMeilisearchIntegration() {
10484
headerContainer = potentialContainers.reduce((prev, current) => {
10585
return (prev.offsetWidth > current.offsetWidth) ? prev : current;
10686
});
107-
console.log('Found flex container in header');
10887
} else {
10988
// Use the header itself as a last resort
11089
headerContainer = header;
111-
console.log('Using header itself as container');
11290
}
11391
}
11492

@@ -119,7 +97,6 @@ function initializeMeilisearchIntegration() {
11997

12098
if (searchParent) {
12199
headerContainer = searchParent;
122-
console.log('Using original search button parent as container');
123100
}
124101
}
125102

@@ -172,7 +149,6 @@ function initializeMeilisearchIntegration() {
172149

173150
// If the header isn't a flex container, we need to make it one for proper centering
174151
if (!isFlexContainer) {
175-
console.log('Container is not flex, creating flex wrapper');
176152
// Create a wrapper to center the search bar
177153
const flexWrapper = document.createElement('div');
178154
flexWrapper.style.cssText = `
@@ -184,7 +160,6 @@ function initializeMeilisearchIntegration() {
184160
flexWrapper.appendChild(searchBarContainer);
185161
headerContainer.appendChild(flexWrapper);
186162
} else {
187-
console.log('Container is already flex, adding directly');
188163
// Insert the search container into the flex container
189164
// Find the right position - ideally in the middle
190165
const childCount = headerContainer.children.length;
@@ -393,18 +368,15 @@ function initializeMeilisearchIntegration() {
393368
// ========= Step 4: Set up Meilisearch for searching =========
394369
// Load Meilisearch client
395370
if (!window.meilisearch) {
396-
console.log('Loading Meilisearch client');
397371
const meilisearchScript = document.createElement('script');
398372
meilisearchScript.src = 'https://cdn.jsdelivr.net/npm/meilisearch@latest/dist/bundles/meilisearch.umd.js';
399373
meilisearchScript.onload = () => {
400-
console.log('Meilisearch client loaded');
401374
// The UMD bundle exposes MeiliSearch directly, no need to access .default
402375
window.meilisearch = window.MeiliSearch;
403376
setupMeilisearchHandlers(searchInput, resultsContainer);
404377
};
405378
document.head.appendChild(meilisearchScript);
406379
} else {
407-
console.log('Meilisearch client already loaded');
408380
setupMeilisearchHandlers(searchInput, resultsContainer);
409381
}
410382

@@ -424,13 +396,10 @@ function initializeMeilisearchIntegration() {
424396
// Set up the search functionality
425397
const setupMeilisearchHandlers = (searchInput, resultsContainer) => {
426398
try {
427-
console.log('Setting up Meilisearch handlers');
428399
const client = new window.meilisearch({
429400
host: MEILISEARCH_HOST,
430401
apiKey: MEILISEARCH_API_KEY
431402
});
432-
433-
console.log(client);
434403

435404
const index = client.index(MEILISEARCH_INDEX);
436405

@@ -447,7 +416,6 @@ function initializeMeilisearchIntegration() {
447416
}
448417

449418
debounceTimer = setTimeout(() => {
450-
console.log('Searching for:', query);
451419
// Show loading indicator
452420
resultsContainer.innerHTML = '<div style="padding: 20px; text-align: center; color: rgba(255, 255, 255, 0.7);">Searching...</div>';
453421

@@ -463,7 +431,6 @@ function initializeMeilisearchIntegration() {
463431
}
464432
})
465433
.then(response => {
466-
console.log('Search results:', response.hits.length);
467434
resultsContainer.innerHTML = '';
468435

469436
if (response.hits.length === 0) {
@@ -589,8 +556,7 @@ function initializeMeilisearchIntegration() {
589556
const searchBarContainer = document.getElementById('meilisearch-bar-container') ||
590557
document.getElementById('search-bar-entry');
591558

592-
if (!searchBar && !searchBarContainer) {
593-
console.log('Search bar missing in desktop view, reinitializing');
559+
if (!searchBar && !searchBarContainer) { //searchbar missing in desktop view, reinitialize
594560
initSearchBar();
595561
}
596562
}
@@ -611,12 +577,8 @@ function initializeMeilisearchIntegration() {
611577
}
612578

613579
// Initialization
614-
if (document.readyState === 'complete' || document.readyState === 'interactive') {
615-
console.log('Document ready, initializing');
580+
if (document.readyState === 'complete' || document.readyState === 'interactive') { //document ready, initialize
616581
initializeMeilisearchIntegration();
617-
} else {
618-
console.log('Waiting for DOMContentLoaded');
582+
} else { //waiting for DOMContentLoaded, initialize
619583
document.addEventListener('DOMContentLoaded', initializeMeilisearchIntegration);
620-
}
621-
622-
console.log('Meilisearch search script loaded');
584+
}

0 commit comments

Comments
 (0)