Skip to content

Commit

Permalink
feat(docsearch): adapt module to config options (#638)
Browse files Browse the repository at this point in the history
  • Loading branch information
clemcode authored Sep 29, 2022
1 parent 55f0b1f commit 14d63a8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
10 changes: 5 additions & 5 deletions theme/app/integrations/docsearch.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { withoutTrailingSlash } from 'ufo'
import type { DocSearchOptions } from '@nuxtjs/algolia/dist/module.d'

export default defineNuxtPlugin(async () => {
export default defineNuxtPlugin(() => {
const config = useRuntimeConfig()

const docSearchElement = ref()

const hasDocSearch = computed(() => config?.algolia?.docSearch)
const hasDocSearch = computed(() => config?.public?.algolia?.docSearch)

// Setup Algolia DocSearch integration
if (hasDocSearch.value) {
Expand All @@ -23,7 +23,7 @@ export default defineNuxtPlugin(async () => {
const { algolia } = useRuntimeConfig()

if (algolia && algolia.docSearch) {
return algolia.docSearch
return algolia
}

return {}
Expand Down Expand Up @@ -70,7 +70,7 @@ export default defineNuxtPlugin(async () => {
const langPrefix = `${userOptions.langAttribute || 'language'}:${lang}`

// Get facet filters
const userFacetFilters = userOptions.facetFilters || []
const userFacetFilters = userOptions.docSearch.facetFilters || []

// Create DocSearch instance
docsearch({
Expand All @@ -80,7 +80,7 @@ export default defineNuxtPlugin(async () => {
container: el,
appId: userOptions.applicationId,
apiKey: userOptions.apiKey,
indexName: userOptions.indexName,
indexName: userOptions.docSearch.indexName,
searchParameters: {
...(!lang
? {
Expand Down
14 changes: 7 additions & 7 deletions theme/app/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ export default defineNuxtModule({
version: '3.0.0',
compatibility: {
nuxt: '^3.0.0-rc.4',
bridge: false,
bridge: false
},
configKey: 'docus',
configKey: 'docus'
},
setup(_, nuxt) {
setup (_, nuxt) {
// Pre-render 404 page
/*
nuxt.hook('nitro:config', (nitroConfig) => {
Expand All @@ -38,15 +38,15 @@ export default defineNuxtModule({
// @ts-expect-error - GitHub module might not be installed
if (nuxt.options?.github) {
addPlugin({
src: resolveThemeDir('integrations/github.ts'),
src: resolveThemeDir('integrations/github.ts')
})
}

// @ts-expect-error - Algolia module might not be installed
if (nuxt.options?.algolia?.docSearch) {
if (nuxt.options?.runtimeConfig?.public?.algolia?.docSearch) {
addPlugin({
src: resolveThemeDir('integrations/docsearch.ts'),
src: resolveThemeDir('integrations/docsearch.ts')
})
}
},
}
})
3 changes: 2 additions & 1 deletion theme/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export default defineNuxtConfig({
'@nuxtjs/color-mode',
'@nuxtjs/tailwindcss',
'@nuxt/content',
'@vueuse/nuxt'
'@vueuse/nuxt',
resolve('./app/module')
],

css: [
Expand Down

1 comment on commit 14d63a8

@vercel
Copy link

@vercel vercel bot commented on 14d63a8 Sep 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.