({ children })
| 8 | import { searchLinks } from '@/data/config/searchLinks'; |
| 9 | |
| 10 | export const SearchProvider = ({ children }) => { |
| 11 | const router = useRouter(); |
| 12 | |
| 13 | const makeRootPath = (path: string) => { |
| 14 | if (!path.startsWith('/')) { |
| 15 | return `/${path}`; |
| 16 | } |
| 17 | |
| 18 | return path; |
| 19 | }; |
| 20 | |
| 21 | return ( |
| 22 | <KBarSearchProvider |
| 23 | kbarConfig={{ |
| 24 | searchDocumentsPath: 'search.json', |
| 25 | onSearchDocumentsLoad(json) { |
| 26 | return [ |
| 27 | ...searchLinks.map((link) => { |
| 28 | return { |
| 29 | id: link.id, |
| 30 | name: link.name, |
| 31 | keywords: link.keywords, |
| 32 | section: link.section, |
| 33 | perform: () => router.push(link.href), |
| 34 | }; |
| 35 | }), |
| 36 | |
| 37 | ...json.map((post: CoreContent<Blog>) => ({ |
| 38 | id: post.path, |
| 39 | name: post.title, |
| 40 | keywords: post?.summary || '', |
| 41 | section: 'Pages', |
| 42 | subtitle: `${ |
| 43 | post.date ? `${formatDate(post.date, 'en-US')}` : '' |
| 44 | }`, |
| 45 | perform: () => router.push(makeRootPath(post.path)), |
| 46 | })), |
| 47 | ]; |
| 48 | }, |
| 49 | }} |
| 50 | > |
| 51 | {children} |
| 52 | </KBarSearchProvider> |
| 53 | ); |
| 54 | }; |
nothing calls this directly
no outgoing calls
no test coverage detected