|
1 | 1 | import { loadConfig, watchConfig, createDefineConfig } from 'c12' |
2 | 2 | import { relative } from 'pathe' |
| 3 | +import { hasNuxtModule, useNuxt } from '@nuxt/kit' |
3 | 4 | import type { Nuxt } from '@nuxt/schema' |
4 | 5 | import type { DefinedCollection, ModuleOptions } from '../types' |
5 | 6 | import { defineCollection, resolveCollections } from './collection' |
6 | 7 | import { logger } from './dev' |
| 8 | +import { resolveStudioCollection } from './studio' |
7 | 9 |
|
8 | 10 | type NuxtContentConfig = { |
9 | 11 | collections: Record<string, DefinedCollection> |
10 | 12 | } |
11 | 13 |
|
12 | | -const defaultConfig: NuxtContentConfig = { |
13 | | - collections: { |
14 | | - content: defineCollection({ |
15 | | - type: 'page', |
16 | | - source: '**/*', |
17 | | - }), |
18 | | - }, |
19 | | -} |
| 14 | +const createDefaultCollections = (): NuxtContentConfig['collections'] => ({ |
| 15 | + content: defineCollection({ |
| 16 | + type: 'page', |
| 17 | + source: '**/*', |
| 18 | + }), |
| 19 | +}) |
20 | 20 |
|
21 | 21 | export const defineContentConfig = createDefineConfig<NuxtContentConfig>() |
22 | 22 |
|
@@ -68,7 +68,14 @@ export async function loadContentConfig(nuxt: Nuxt, options?: ModuleOptions) { |
68 | 68 | logger.warn('No content configuration found, falling back to default collection. In order to have full control over your collections, create the config file in project root. See: https://content.nuxt.com/docs/getting-started/installation') |
69 | 69 | } |
70 | 70 |
|
71 | | - const collections = resolveCollections(hasNoCollections ? defaultConfig.collections : collectionsConfig) |
| 71 | + const finalCollectionsConfig = hasNoCollections ? createDefaultCollections() : collectionsConfig |
| 72 | + |
| 73 | + // If nuxt-studio is installed, automatically configure studio collection |
| 74 | + if (hasNuxtModule('nuxt-studio', nuxt || useNuxt())) { |
| 75 | + resolveStudioCollection(nuxt, finalCollectionsConfig) |
| 76 | + } |
| 77 | + |
| 78 | + const collections = resolveCollections(finalCollectionsConfig) |
72 | 79 |
|
73 | 80 | return { collections } |
74 | 81 | } |
0 commit comments