@@ -6,7 +6,7 @@ const Search = ({ isVisible }) => {
66 const [ searchTerm , setSearchTerm ] = useState ( '' ) ;
77 const [ searchResults , setSearchResults ] = useState ( [ ] ) ;
88 const [ isDropdownOpen , setIsDropdownOpen ] = useState ( false ) ;
9- const [ data , setData ] = useState ( { posts : [ ] , projects : [ ] , logs : [ ] } ) ;
9+ const [ data , setData ] = useState ( { posts : [ ] , projects : [ ] , logs : [ ] , routes : [ ] } ) ; // Add routes to data
1010 const searchRef = useRef ( null ) ;
1111
1212 useEffect ( ( ) => {
@@ -26,7 +26,20 @@ const Search = ({ isVisible }) => {
2626 item . series ? item . series . posts . map ( p => ( { ...p , series : item . title } ) ) : item
2727 ) ;
2828
29- setData ( { posts : allPosts , projects, logs } ) ;
29+ // Manually define common routes
30+ const routes = [
31+ { title : 'Home' , slug : '/' , type : 'route' } ,
32+ { title : 'Blogs' , slug : '/blog' , type : 'route' } ,
33+ { title : 'Projects' , slug : '/projects' , type : 'route' } ,
34+ { title : 'About Me' , slug : '/about' , type : 'route' } ,
35+ { title : 'Logs' , slug : '/logs' , type : 'route' } ,
36+ { title : 'Settings' , slug : '/settings' , type : 'route' } ,
37+ { title : 'Dungeons and Dragons' , slug : '/dnd' , type : 'route' } ,
38+ { title : 'Apps' , slug : '/apps' , type : 'route' } ,
39+ { title : 'Random' , slug : '/random' , type : 'route' } ,
40+ ] ;
41+
42+ setData ( { posts : allPosts , projects, logs, routes } ) ; // Include routes in data
3043 } catch ( error ) {
3144 console . error ( 'Failed to fetch search data:' , error ) ;
3245 }
@@ -63,7 +76,16 @@ const Search = ({ isVisible }) => {
6376 )
6477 . map ( ( log ) => ( { ...log , type : 'log' } ) ) ;
6578
66- setSearchResults ( [ ...posts , ...projects , ...logs ] ) ;
79+ // Filter routes
80+ const routes = data . routes
81+ . filter (
82+ ( route ) =>
83+ route . title . toLowerCase ( ) . includes ( lowerCaseSearchTerm ) ||
84+ route . slug . toLowerCase ( ) . includes ( lowerCaseSearchTerm )
85+ )
86+ . map ( ( route ) => ( { ...route , type : 'route' } ) ) ;
87+
88+ setSearchResults ( [ ...posts , ...projects , ...logs , ...routes ] ) ; // Include routes in search results
6789 setIsDropdownOpen ( true ) ;
6890 } else {
6991 setSearchResults ( [ ] ) ;
@@ -92,6 +114,8 @@ const Search = ({ isVisible }) => {
92114 return `/projects/${ result . slug } ` ;
93115 case 'log' :
94116 return `/logs/${ result . slug } ` ;
117+ case 'route' : // Handle routes
118+ return result . slug ;
95119 default :
96120 return '/' ;
97121 }
0 commit comments