diff --git a/src/components/Header.astro b/src/components/Header.astro index 65080b0..44539f9 100644 --- a/src/components/Header.astro +++ b/src/components/Header.astro @@ -423,9 +423,9 @@ const currentPath = Astro.url.pathname; } }); - // Search functionality - client-side post filtering - const searchResults = document.getElementById('search-results'); - + // Search functionality - client-side site-wide filtering (User provided version) + const searchResults = document.getElementById('search-results'); // Assuming this ID exists in your dropdown HTML + // Function to perform search const performSearch = async (query) => { if (!query || query.length < 2) { @@ -437,39 +437,68 @@ const currentPath = Astro.url.pathname; } try { - // This would ideally be a server-side search or a pre-built index - // For now, we'll just fetch all posts and filter client-side - const response = await fetch('/search-index.json'); + // Fetch the search index that contains all site content + const response = await fetch('/search-index.json'); // Ensure this path is correct based on your build output if (!response.ok) throw new Error('Failed to fetch search data'); - const posts = await response.json(); - const results = posts.filter(post => { + const allContent = await response.json(); + const results = allContent.filter(item => { const lowerQuery = query.toLowerCase(); return ( - post.title.toLowerCase().includes(lowerQuery) || - post.description?.toLowerCase().includes(lowerQuery) || - post.tags?.some(tag => tag.toLowerCase().includes(lowerQuery)) + item.title.toLowerCase().includes(lowerQuery) || + item.description?.toLowerCase().includes(lowerQuery) || + item.tags?.some(tag => tag.toLowerCase().includes(lowerQuery)) || + item.category?.toLowerCase().includes(lowerQuery) ); - }).slice(0, 5); // Limit to 5 results + }).slice(0, 8); // Limit to 8 results for better UI // Display results if (searchResults) { if (results.length > 0) { - searchResults.innerHTML = results.map(post => ` -
Select a post in the graph to view its content here
+Select a post in the graph to view its content
+