feat(content): add defineSitemapSchema() composable#576
Merged
Conversation
…t v3 Replaces the `asSitemapCollection()` wrapper with a schema-level composable that users add directly to their collection schema. This is less fragile because it doesn't mutate the collection object or depend on schema merge ordering. Supports an optional `z` parameter for cross-version Zod compat with @nuxt/content's `.editor()` patch. The old `asSitemapCollection()` is kept but deprecated. Resolves harlan-zw/nuxt-seo#519
6 tasks
There was a problem hiding this comment.
Pull request overview
Adds a new Nuxt Content integration API (defineSitemapSchema()) to avoid asSitemapCollection()’s collection mutation / merge-order issues (nuxt-seo#519), and updates docs + E2E coverage to validate the new approach.
Changes:
- Introduce
defineSitemapSchema()insrc/content.ts(and deprecateasSitemapCollection()). - Add a new Nuxt Content v3 fixture + E2E test validating schema inclusion, filtering, and frontmatter preservation.
- Update Nuxt Content guide to document the new API.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| test/fixtures/content-v3-define-schema/pages/[...slug].vue | Minimal page to render Content in the new fixture app. |
| test/fixtures/content-v3-define-schema/nuxt.config.ts | Fixture Nuxt config enabling sitemap + content modules. |
| test/fixtures/content-v3-define-schema/content/published.md | Fixture content entry expected to be included in sitemap. |
| test/fixtures/content-v3-define-schema/content/future.md | Fixture content entry expected to be filtered out (future date). |
| test/fixtures/content-v3-define-schema/content/foo.md | Fixture content entry expected to be included; used for priority assertion. |
| test/fixtures/content-v3-define-schema/content/draft.md | Fixture content entry expected to be filtered out (draft). |
| test/fixtures/content-v3-define-schema/content/bar.md | Additional included fixture content entry. |
| test/fixtures/content-v3-define-schema/content.config.ts | Defines collection schema using defineSitemapSchema({ name, filter }). |
| test/fixtures/content-v3-define-schema/app.vue | Fixture app shell. |
| test/e2e/content-v3/define-schema.test.ts | E2E tests covering inclusion, filtering, and frontmatter passthrough. |
| src/content.ts | Implements defineSitemapSchema(), refactors sitemap schema building, deprecates legacy wrapper. |
| docs/content/1.guides/4.content.md | Updates Nuxt Content guide to use defineSitemapSchema() API. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Warns at build time when asSitemapCollection() is used. Throws a clear error with migration link if someone passes a collection config to defineSitemapSchema() (naive find-and-replace of function name).
harlan-zw
added a commit
to harlan-zw/nuxt-schema-org
that referenced
this pull request
Mar 22, 2026
Replace the `asSchemaOrgCollection()` wrapper pattern with a `defineSchemaOrgSchema()` composable that returns the schema field directly for users to compose into their own `schema: z.object()`. This avoids schema merge ordering issues and aligns with the sitemap module's approach (nuxt-modules/sitemap#576). `asSchemaOrgCollection()` is kept but marked `@deprecated`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔗 Linked issue
Resolves harlan-zw/nuxt-seo#519
❓ Type of change
📚 Description
The
asSitemapCollection()wrapper mutates the collection object and depends on schema merge ordering, which caused Nuxt Studio to show injected sitemap fields and trigger conflict detection (nuxt-seo#519).defineSitemapSchema()is a new composable that returns the sitemap Zod schema directly for users to compose into their ownschema: z.object(). It accepts an optionalzparameter so users can pass the@nuxt/contentpatched Zod instance, ensuring.editor({ hidden: true })works across Zod versions. SupportsfilterandonUrlcallbacks, same as the old API.asSitemapCollection()is kept but marked@deprecated.