@@ -20,7 +20,7 @@ const defaultConfig: NuxtContentConfig = {
20
20
21
21
export const defineContentConfig = createDefineConfig < NuxtContentConfig > ( )
22
22
23
- export async function loadContentConfig ( nuxt : Nuxt , options : { defaultFallback ?: boolean } = { } ) {
23
+ export async function loadContentConfig ( nuxt : Nuxt ) {
24
24
const loader : typeof watchConfig = nuxt . options . dev
25
25
? opts => watchConfig ( {
26
26
...opts ,
@@ -37,7 +37,7 @@ export async function loadContentConfig(nuxt: Nuxt, options: { defaultFallback?:
37
37
const layers = [ ...nuxt . options . _layers ] . reverse ( )
38
38
const contentConfigs = await Promise . all (
39
39
layers . map (
40
- layer => loader < NuxtContentConfig > ( { name : 'content' , cwd : layer . config . rootDir , defaultConfig : options . defaultFallback ? defaultConfig : undefined } ) ,
40
+ layer => loader < NuxtContentConfig > ( { name : 'content' , cwd : layer . config . rootDir , defaultConfig : { collections : { } } } ) ,
41
41
) ,
42
42
)
43
43
@@ -48,9 +48,21 @@ export async function loadContentConfig(nuxt: Nuxt, options: { defaultFallback?:
48
48
nuxt . hook ( 'close' , ( ) => Promise . all ( contentConfigs . map ( c => c . unwatch ( ) ) ) . then ( ( ) => { } ) )
49
49
}
50
50
51
- const collectionsConfig = contentConfigs . reduce ( ( acc , curr ) => ( { ...acc , ...curr . config ?. collections } ) , { } as Record < string , DefinedCollection > )
52
- const hasNoCollections = Object . keys ( collectionsConfig || { } ) . length === 0
51
+ const collectionsConfig = contentConfigs . reduce ( ( acc , curr ) => {
52
+ const layerCollections = curr . config ?. collections || { }
53
+ const cwd = curr . cwd !
54
+
55
+ Object . entries ( layerCollections ) . forEach ( ( [ name , collection ] ) => {
56
+ // @ts -expect-error - `__rootDir` is a private property to store the layer's cwd
57
+ collection . __rootDir = cwd
58
+
59
+ acc [ name ] = collection
60
+ } )
61
+
62
+ return acc
63
+ } , { } as Record < string , DefinedCollection > )
53
64
65
+ const hasNoCollections = Object . keys ( collectionsConfig || { } ) . length === 0
54
66
if ( hasNoCollections ) {
55
67
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' )
56
68
}
0 commit comments