Skip to content

Follow Nuxt Content collections for routes and variable schemas - #52

Merged
xprees merged 1 commit into
masterfrom
ccr-f27f9a8d-ohbasu-collections
Nov 16, 2026
Merged

xprees merged 1 commit into
masterfrom
ccr-f27f9a8d-ohbasu-collections

Conversation

@xprees

@xprees xprees commented Nov 16, 2026

Copy link
Copy Markdown
Owner

What and why

Reported with a real content.config.ts. It has four page collections (pages_en, pages_cs, threats_en, threats_cs), each with source: { include, prefix }, and schemas held in variables (pageSchema.passthrough().extend({...}), threatSchema.extend({...})).

I reproduced that project in a test. File detection works on master: every file in all four collections is Comark and matches its own collection. Two real gaps showed up:

  1. Route links ignored collections. /threats/phishing, /cs/hrozby/phishing, /about and /cs/o-nas didn't resolve; only the raw directory paths did.
  2. Schemas held in variables were unknown. Every collection got schemaKnown = false with no fields, so the Nuxt Studio style couldn't apply Studio's defaults (toc: false, icon, category).

Changes

  • Routes (ComarkContentRoutes), checked against @nuxt/content 3.16.2 (defineLocalSource, parseSourceBase, describeId, generatePath):
    • With collections in content.config.*, routes come from the page collections: the files below each source's cwd that match include and not exclude.
    • Each route is prefix followed by the file's path below the static part of include. Without a prefix, the static part itself is used.
    • Segments are refined as Nuxt does: ordering prefixes, index and .draft are dropped, and segments are slugified.
    • Data collections have no routes.
    • A front matter path: overrides the route. This also applies with the default routing.
    • Without collections, the default content/ routing is unchanged.
    • The cache is invalidated on file structure changes, Comark PSI changes and configuration changes.
  • Schemas (ComarkCollections.resolveSchema):
    • const x = z.object({...}) (also with a type annotation, over several lines) is followed.
    • .extend(), .merge() and .safeExtend() add or replace fields; a replaced field keeps its place.
    • .omit() and .pick() drop fields.
    • .passthrough(), .partial(), .describe() and similar calls keep the fields.
    • Imports, spreads and other calls (.transform(), .and()) stay unknown.
  • Sources: ComarkCollections.Source now carries prefix, fixed and routePrefix.

How it was tested

  • ComarkCollectionRoutesTest (new): prefixes (/, /cs, /threats), the default prefix with slugified segments, a front matter path override, exclude, data collections, and collectionRoute cases.
  • ComarkCollectionsTest: schemas in variables (extend / merge / omit / pick / partial, replaced field position, imported → unknown), spread and transform → unknown, and source prefix and fixed part. The old assertion that "a schema in a variable is unknown" now expects the resolved schema.
  • ComarkRouteReferenceTest (default routing) is unchanged and passes.
  • ./gradlew test: 903 tests, 0 failures.

Generated by Claude Code

Route links now follow the page collections of content.config.ts as
Nuxt Content 3.16 builds routes: each source's files below cwd that
match include and not exclude, routed as prefix (by default the
static part of include) plus the path below that static part. A path
in a page's front matter overrides the route. Without collections the
default content/ routing is unchanged.

Collection schemas held in variables are resolved, with .extend(),
.merge(), .omit(), .pick() and field-keeping calls such as
.passthrough(); imported schemas and other calls stay unknown.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KGGeqcwjamvMDTrazMJWkz
@xprees
xprees merged commit 38648f5 into master Nov 16, 2026
7 checks passed
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.

2 participants