Skip to content

Commit 98fc0c7

Browse files
committed
add faq with kbar customization
1 parent bb7a8db commit 98fc0c7

File tree

1 file changed

+61
-1
lines changed

1 file changed

+61
-1
lines changed

README.md

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Feature request? Check the past discussions to see if it has been brought up pre
2424
- [Demo Blog](https://tailwind-nextjs-starter-blog.vercel.app/) - this repo
2525
- [My personal blog](https://www.timlrx.com) - modified to auto-generate blog posts with dates
2626
- [ben.codes blog](https://ben.codes) - Benoit's personal blog about software development ([source code](https://github.com/bendotcodes/bendotcodes))
27-
- [tsix blog](https://tsix.top) - A front-end engineer is used to record some knowledge points in work and study *中文*
27+
- [tsix blog](https://tsix.top) - A front-end engineer is used to record some knowledge points in work and study _中文_
2828

2929
Using the template? Feel free to create a PR and add your blog to this list.
3030

@@ -252,6 +252,66 @@ See [Next.js on Netlify](https://docs.netlify.com/integrations/frameworks/next-j
252252
5. Run `yarn build`. The generated static content is in the `out` folder.
253253
6. Deploy the `out` folder to your hosting service of choice or run `npx serve out` to view the website locally.
254254

255+
## Frequently Asked Questions
256+
257+
### How can I customize the `kbar` search?
258+
259+
Add a `SearchProvider` component such as the one shown below and use it in place of the default `SearchProvider` component in `app/layout.tsx`.
260+
261+
`defaultActions` are the initial list of actions.
262+
263+
`onSearchDocumentsLoad` is a callback function that is called when the documents specified by `searchDocumentsPath` are loaded. Set `searchDocumentsPath` to `false` to disable the dynamically loaded search feature.
264+
265+
```tsx
266+
'use client'
267+
268+
import { KBarSearchProvider } from 'pliny/search/KBar'
269+
import { useRouter } from 'next/navigation'
270+
import { CoreContent } from 'pliny/utils/contentlayer'
271+
import { Blog } from 'contentlayer/generated'
272+
273+
export const SearchProvider = ({ children }) => {
274+
const router = useRouter()
275+
return (
276+
<KBarSearchProvider
277+
kbarConfig={{
278+
searchDocumentsPath: 'search.json',
279+
defaultActions: [
280+
{
281+
id: 'homepage',
282+
name: 'Homepage',
283+
keywords: '',
284+
shortcut: ['h', 'h'],
285+
section: 'Home',
286+
perform: () => router.push('/'),
287+
},
288+
{
289+
id: 'projects',
290+
name: 'Projects',
291+
keywords: '',
292+
shortcut: ['p'],
293+
section: 'Home',
294+
perform: () => router.push('/projects'),
295+
},
296+
],
297+
onSearchDocumentsLoad(json) {
298+
return json.map((post: CoreContent<Blog>) => ({
299+
id: post.path,
300+
name: post.title,
301+
keywords: post?.summary || '',
302+
section: 'Blog',
303+
subtitle: post.tags.join(', '),
304+
perform: () => router.push(post.path),
305+
}))
306+
},
307+
}}
308+
>
309+
{children}
310+
</KBarSearchProvider>
311+
)
312+
}
313+
```
314+
255315
## Support
256316
257317
Using the template? Support this effort by giving a star on GitHub, sharing your own blog and giving a shoutout on Twitter or becoming a project [sponsor](https://github.com/sponsors/timlrx).

0 commit comments

Comments
 (0)