-
Notifications
You must be signed in to change notification settings - Fork 64
fix(collection): only match root sources in getCollectionByFilePath #286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(collection): only match root sources in getCollectionByFilePath #286
Conversation
source.cwd is always empty after @nuxt/content resolves it. Use source.prefix to filter non-root sources (e.g., /docs). Fixes nuxt-content#235 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
@naitokosuke is attempting to deploy a commit to the Nuxt Team on Vercel. A member of the Team first needs to authorize it. |
commit: |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Hey @naitokosuke, thanks for your feedback and detailed issue and PR. I confirm the issue you're facing since we do not handle Your fix did fix your case but it does not make sense in all cases. The That being said, the By doing so you could just update your collections definition to have: // content.config.ts
const content = defineCollection({
type: "page",
source: "**/*.{md,yml,json}", // content directory
exclude: ["docs/**"]
})
const docs = defineCollection({
type: "page",
source: {
include: "docs/**/*.md",
prefix: "/docs"
},
})And this might work as expected. Tell me if it's not the case. |
|
Thank you for the detailed explanation — I realize now that I had misunderstood the intent around prefix and cwd. Your clarification makes a lot of sense, especially regarding how prefix is fundamentally about route generation rather than filesystem context. I’ll try the approach you suggested by placing the docs folder inside the content directory and adjusting the collections accordingly. Thank you as well for taking the time to explain this so clearly, and for confirming the behavior on the Studio side. Congratulations on the Studio v1 release — it’s a great milestone. I’m really looking forward to seeing how it continues to evolve. Thanks again for everything, and keep up the great work. |
Reverts from fork branch to official ^1.1.0 release. The fork was used for testing PR nuxt-content/nuxt-studio#286, which will not be merged. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Nuxt Studio does not support `cwd` option for collections. Moving docs inside content directory allows using include/exclude patterns instead. Refs: nuxt-content/nuxt-studio#286 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* fix: revert nuxt-studio to official package Reverts from fork branch to official ^1.1.0 release. The fork was used for testing PR nuxt-content/nuxt-studio#286, which will not be merged. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: move docs/ into content/docs/ Nuxt Studio does not support `cwd` option for collections. Moving docs inside content directory allows using include/exclude patterns instead. Refs: nuxt-content/nuxt-studio#286 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: update content.config.ts for Nuxt Studio compatibility - Add exclude pattern for docs in content collection - Update docs collection to use include pattern instead of cwd - Remove unsupported cwd option Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * chore: update pnpm-lock.yaml Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Summary
Thank you for maintaining this amazing project! 🙏
This PR fixes an issue where
getCollectionByFilePathincorrectly matches files from thecontentdirectory to collections with non-root prefixes (e.g.,/docs).Problem
When using multiple collections with different
cwdvalues:Selecting a file like
content/dev-env-2026/index.mdin Studio throws:Root Cause
getCollectionByFilePathsorts collections by prefix length (longer first)dev-env-2026/index.md, thedocscollection is checked firstminimatch('dev-env-2026/index.md', '**/*.md')returnstruedocscollectiongenerateIdFromFsPathcreates an invalid IDWhy
source.cwddoesn't workI initially tried filtering by
source.cwd, but discovered that@nuxt/content'sdefineLocalSourcealways setscwd: ""at the end:Solution
Filter sources by
source.prefixinstead:This ensures that files from the
contentdirectory (passed as relative paths) only match collections with root prefix (/).Testing
I couldn't find documentation on how to run the Studio editor locally for testing. So I verified this fix by:
dist/includeddist/to my fork branch"nuxt-studio": "github:naitokosuke/nuxt-studio#fix/get-collection-by-file-path"/_studiodirectlycontent/dev-env-2026/index.mdno longer throws errorsIf there's a recommended way to test Studio locally, I'd appreciate guidance for future contributions!
Related
Fixes #235