From 14d63a828790b8ec340d22d964dc93d67f06a98f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Ollivier?= Date: Thu, 29 Sep 2022 14:18:52 +0200 Subject: [PATCH] feat(docsearch): adapt module to config options (#638) --- theme/app/integrations/docsearch.ts | 10 +++++----- theme/app/module.ts | 14 +++++++------- theme/nuxt.config.ts | 3 ++- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/theme/app/integrations/docsearch.ts b/theme/app/integrations/docsearch.ts index a6e3456cd..896a8a2bd 100644 --- a/theme/app/integrations/docsearch.ts +++ b/theme/app/integrations/docsearch.ts @@ -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) { @@ -23,7 +23,7 @@ export default defineNuxtPlugin(async () => { const { algolia } = useRuntimeConfig() if (algolia && algolia.docSearch) { - return algolia.docSearch + return algolia } return {} @@ -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({ @@ -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 ? { diff --git a/theme/app/module.ts b/theme/app/module.ts index 208aa03db..974141442 100644 --- a/theme/app/module.ts +++ b/theme/app/module.ts @@ -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) => { @@ -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') }) } - }, + } }) diff --git a/theme/nuxt.config.ts b/theme/nuxt.config.ts index f9572b1f1..7038d9968 100644 --- a/theme/nuxt.config.ts +++ b/theme/nuxt.config.ts @@ -8,7 +8,8 @@ export default defineNuxtConfig({ '@nuxtjs/color-mode', '@nuxtjs/tailwindcss', '@nuxt/content', - '@vueuse/nuxt' + '@vueuse/nuxt', + resolve('./app/module') ], css: [