Skip to content

feat(collection): add slugFields for multi-segment collection paths (#340) - #1660

Open
rxhtt wants to merge 1 commit into
Thinkmill:mainfrom
rxhtt:feat/multi-segment-slug-fields
Open

rxhtt wants to merge 1 commit into
Thinkmill:mainfrom
rxhtt:feat/multi-segment-slug-fields

Conversation

@rxhtt

@rxhtt rxhtt commented Nov 10, 2026

Copy link
Copy Markdown

Summary

Implements #340 using the static, deterministic API proposed and discussed in the issue: collections can declare multiple slug fields that map onto the * segments of the collection path in order.

collection({
  path: 'src/content/blog/*/*',
  slugFields: ['locale', 'title'],
  slugField: 'title',
  schema: {
    locale: fields.text({ label: 'Locale' }),
    title: fields.slug({ name: { label: 'Title' } }),
  },
})

An entry with locale en and title slug my-post is stored at src/content/blog/en/my-post. The entry's slug is the segments joined with a slash (en/my-post), which keeps tree listing, routing, the reader, and GitHub/local storage backends deterministic — without non-serializable function callbacks.

  • Fully backwards compatible: single slugField collections behave exactly as before.
  • Config validation: star count must match slugFields.length, every entry must be a slug field, and the last entry must be the primary slugField.
  • Composite slug validation: secondary slug fields validate as slug segments while the primary field checks uniqueness against the full composite slug.
  • Fully tested: comprehensive suite added in slug-fields.test.ts (100% green on tsc --noEmit and vitest).

Fixes #340
/claim #340

…hinkmill#340)

- Support multi-segment wildcard collection paths without non-serializable callbacks
- Map slug segments to schema fields deterministically
- Maintain full compatibility with single slugField collections
- Include comprehensive unit tests across path parsing and reader listing
- Add changeset and update collection documentation

Fixes Thinkmill#340
/claim Thinkmill#340

This branch has not been deployed

No deployments
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.

Enhancement: more configurable collection path

1 participant