N
Nuxt4w ago
FoxCode

[Content 3] Multiple sources

According to https://content.nuxt.com/docs/collections/sources Can I create collection with multiple sources? For example:
posts: {
source: [{
include: '**/*.md' // Normal content/... md files
}{
cwd: path.resolve('packages/my-pkg/docs'),
include: '**/*.md' // and docs files, everything as posts
}]
}
posts: {
source: [{
include: '**/*.md' // Normal content/... md files
}{
cwd: path.resolve('packages/my-pkg/docs'),
include: '**/*.md' // and docs files, everything as posts
}]
}
Nuxt Content
Sources - Nuxt Content
Learn how to import your files in Nuxt Content collections.
2 Replies
kapa.ai
kapa.ai4w ago
Hi @FoxCode. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Yes, you can create a collection with multiple sources in Nuxt Content v3. According to the Collections Sources documentation, you can define multiple sources for your collections in the content.config.ts file. However, the syntax in your example is not quite correct. Here's the correct way to define multiple sources for a collection:
import { defineCollection, defineContentConfig } from '@nuxt/content'
import path from 'path'

export default defineContentConfig({
collections: {
posts: defineCollection({
source: [
{
include: '**/*.md' // Normal content/... md files
},
{
cwd: path.resolve('packages/my-pkg/docs'),
include: '**/*.md' // and docs files, everything as posts
}
]
})
}
})
import { defineCollection, defineContentConfig } from '@nuxt/content'
import path from 'path'

export default defineContentConfig({
collections: {
posts: defineCollection({
source: [
{
include: '**/*.md' // Normal content/... md files
},
{
cwd: path.resolve('packages/my-pkg/docs'),
include: '**/*.md' // and docs files, everything as posts
}
]
})
}
})
In this configuration: 1. The first source includes all Markdown files (**/*.md) from the default content directory. 2. The second source includes all Markdown files from a custom directory (packages/my-pkg/docs). This setup allows you to combine content from different locations into a single collection, which can be very useful for organizing and managing your content across various parts of your project. Remember to adjust the paths according to your project structure. Also, make sure to import the necessary functions (defineCollection, defineContentConfig) from '@nuxt/content' and path from Node.js if you're using path.resolve(). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai4w ago
<@363971301947342848> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?