Skip to content

feat(content): add defineSitemapSchema() composable#576

Merged
harlan-zw merged 4 commits intomainfrom
feat/define-sitemap-schema
Mar 22, 2026
Merged

feat(content): add defineSitemapSchema() composable#576
harlan-zw merged 4 commits intomainfrom
feat/define-sitemap-schema

Conversation

@harlan-zw
Copy link
Copy Markdown
Collaborator

🔗 Linked issue

Resolves harlan-zw/nuxt-seo#519

❓ Type of change

  • 📖 Documentation
  • 🐞 Bug fix
  • 👌 Enhancement
  • ✨ New feature
  • 🧹 Chore
  • ⚠️ Breaking 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 own schema: z.object(). It accepts an optional z parameter so users can pass the @nuxt/content patched Zod instance, ensuring .editor({ hidden: true }) works across Zod versions. Supports filter and onUrl callbacks, same as the old API.

asSitemapCollection() is kept but marked @deprecated.

…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
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() in src/content.ts (and deprecate asSitemapCollection()).
  • 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 harlan-zw merged commit 603e669 into main Mar 22, 2026
7 checks passed
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`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: Injected sitemap frontmatter causes conflicts when editing in production using Nuxt Studio

2 participants