Skip to content

Commit 52d3aa9

Browse files
authored
Merge pull request #697 from timlrx/enhance/kbar
Bump package versions and enhance kbar
2 parents 1347707 + 153e067 commit 52d3aa9

File tree

3 files changed

+198
-158
lines changed

3 files changed

+198
-158
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
- [SOTO's Blog](https://www.atksoto.com/) - A more personalized personal website upgraded from V1 ([source code](https://github.com/acsoto/soto-blog-nextjs))
2929

3030
Using the template? Feel free to create a PR and add your blog to this list.
@@ -253,6 +253,66 @@ See [Next.js on Netlify](https://docs.netlify.com/integrations/frameworks/next-j
253253
5. Run `yarn build`. The generated static content is in the `out` folder.
254254
6. Deploy the `out` folder to your hosting service of choice or run `npx serve out` to view the website locally.
255255

256+
## Frequently Asked Questions
257+
258+
### How can I customize the `kbar` search?
259+
260+
Add a `SearchProvider` component such as the one shown below and use it in place of the default `SearchProvider` component in `app/layout.tsx`.
261+
262+
`defaultActions` are the initial list of actions.
263+
264+
`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.
265+
266+
```tsx
267+
'use client'
268+
269+
import { KBarSearchProvider } from 'pliny/search/KBar'
270+
import { useRouter } from 'next/navigation'
271+
import { CoreContent } from 'pliny/utils/contentlayer'
272+
import { Blog } from 'contentlayer/generated'
273+
274+
export const SearchProvider = ({ children }) => {
275+
const router = useRouter()
276+
return (
277+
<KBarSearchProvider
278+
kbarConfig={{
279+
searchDocumentsPath: 'search.json',
280+
defaultActions: [
281+
{
282+
id: 'homepage',
283+
name: 'Homepage',
284+
keywords: '',
285+
shortcut: ['h', 'h'],
286+
section: 'Home',
287+
perform: () => router.push('/'),
288+
},
289+
{
290+
id: 'projects',
291+
name: 'Projects',
292+
keywords: '',
293+
shortcut: ['p'],
294+
section: 'Home',
295+
perform: () => router.push('/projects'),
296+
},
297+
],
298+
onSearchDocumentsLoad(json) {
299+
return json.map((post: CoreContent<Blog>) => ({
300+
id: post.path,
301+
name: post.title,
302+
keywords: post?.summary || '',
303+
section: 'Blog',
304+
subtitle: post.tags.join(', '),
305+
perform: () => router.push(post.path),
306+
}))
307+
},
308+
}}
309+
>
310+
{children}
311+
</KBarSearchProvider>
312+
)
313+
}
314+
```
315+
256316
## Support
257317
258318
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).

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"lint": "next lint --fix --dir pages --dir app --dir components --dir lib --dir layouts --dir scripts"
1212
},
1313
"dependencies": {
14-
"@next/bundle-analyzer": "13.4.12",
14+
"@next/bundle-analyzer": "13.4.19",
1515
"@tailwindcss/forms": "^0.5.4",
1616
"@tailwindcss/typography": "^0.5.9",
1717
"autoprefixer": "^10.4.13",
@@ -20,10 +20,10 @@
2020
"github-slugger": "^1.4.0",
2121
"gray-matter": "^4.0.2",
2222
"image-size": "1.0.0",
23-
"next": "13.4.12",
23+
"next": "13.4.19",
2424
"next-contentlayer": "0.3.4",
2525
"next-themes": "^0.2.1",
26-
"pliny": "0.1.1",
26+
"pliny": "0.1.2",
2727
"postcss": "^8.4.24",
2828
"react": "18.2.0",
2929
"react-dom": "18.2.0",
@@ -48,7 +48,7 @@
4848
"@typescript-eslint/parser": "^6.1.0",
4949
"cross-env": "^7.0.3",
5050
"eslint": "^8.45.0",
51-
"eslint-config-next": "13.4.12",
51+
"eslint-config-next": "13.4.19",
5252
"eslint-config-prettier": "^8.8.0",
5353
"eslint-plugin-prettier": "^5.0.0",
5454
"husky": "^8.0.0",

0 commit comments

Comments
 (0)