Skip to content

Commit

Permalink
feat: use nuxt search api for showing docs (#681)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Fu <[email protected]>
  • Loading branch information
arashsheyda and antfu committed Jun 27, 2024
1 parent a049c52 commit 52b6468
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 805 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"eslint-plugin-format": "^0.1.2",
"esno": "^4.7.0",
"execa": "^7.2.0",
"gray-matter": "^4.0.3",
"lint-staged": "^15.2.7",
"nuxt": "^3.12.2",
"pathe": "^1.1.2",
Expand Down
24 changes: 10 additions & 14 deletions packages/devtools/client/composables/state-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,20 @@ export function registerCommands(getter: MaybeRefOrGetter<CommandItem[]>) {

let _nuxtDocsCommands: CommandItem[] | undefined

const docsIcons = [
[':components:', 'i-carbon-assembly-cluster'],
[':modules:', 'i-carbon-cube'],
[':commands:', 'i-carbon-terminal'],
[':directory-structure:', 'i-carbon-folder'],
[':composables:', 'i-carbon-function'],
[':getting-started:', 'i-carbon-idea'],
[':api:', 'carbon-api-1'],
]

export async function getNuxtDocsCommands() {
if (!_nuxtDocsCommands) {
const list = await import('../data/nuxt-docs.json').then(i => i.default)
const list = await $fetch<any[]>('https://nuxt.com/api/search.json', {
query: {
select: '_path,title,description,navigation',
},
})
_nuxtDocsCommands = list.map(i => ({
...i,
icon: docsIcons.find(([k]) => i.id.includes(k))?.[1] || 'i-carbon-document-multiple-01',
id: i._path,
title: i.title,
description: i.description,
icon: i.navigation?.icon ?? 'i-carbon-document-multiple-01',
action: () => {
window.open(i.url, '_blank')
window.open(`https://nuxt.com/${i._path}`, '_blank')
},
}))
}
Expand Down
Loading

0 comments on commit 52b6468

Please sign in to comment.