Skip to content
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

Implement legacy collections using glob #11976

Open
wants to merge 38 commits into
base: next
Choose a base branch
from
Open

Implement legacy collections using glob #11976

wants to merge 38 commits into from

Conversation

ascorbic
Copy link
Contributor

@ascorbic ascorbic commented Sep 12, 2024

Changes

Breaking change to legacy content collections, to be merged after 5.0 beta release.

Implements legacy content and data collections using glob() loader. By default, collections that use the the old types (content or data) are now implemented using the glob loader, with extra backward-compat handling. This includes any collection without a loader defined.

Any legacy content collections are handled like this:

  • a glob loader collection is defined, with patterns that match the previous handling (matches src/content/<collection name>/**/*.md and other content extensions depending on installed integrations, with underscore-prefixed files and folders ignored)
  • When used in the runtime, the entries have an ID based on the filename in the same format as legacy collections
  • A slug field is added with the same format as before
  • A render() method is added to the entry, so they can be called using entry.render()
  • getEntryBySlug is supported

Legacy data collections are handled like this:

  • a glob loader collection is defined, with patterns that match the previous handling (matches src/content/<collection name>/**/*{.json,.yaml} and other data extensions, with underscore-prefixed files and folders ignored)
  • Entries have an ID that is not slugified
  • getDataEntryById is supported

While these emulate most of the features of legacy collections, they have these differences:

  • No implicit collections. In order to be generated, a collection must be defined in config.ts. For legacy collections these can just be empty declarations: e.g.const blog = defineCollection({}). Removing implicit collections means that we can allow content layer collections in src/content.
  • The layout field is not supported in Markdown
  • Experimental content collection cache is not supported
  • Sort order of generated collections is non-deterministic and platform-dependent.
  • image().refine() is not supported
  • the key for getEntry is typed as string, rather than having types for every entry.

A new config flag legacy.legacyContentCollections is added for users that need the old behavior. When set, collections in src/content are processed in the same way as before rather than being implemented with glob - including implicit collections. When set, content layer collections are forbidden in src/content, and will fail a build if defined.

Testing

Lots of tests have been updated. Where possible they use the new implementation, but when they need to test unsupported features then they have the legacy flag applied.

Docs

Copy link

changeset-bot bot commented Sep 12, 2024

🦋 Changeset detected

Latest commit: 505b426

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added pkg: astro Related to the core `astro` package (scope) docs pr labels Sep 12, 2024
@ascorbic
Copy link
Contributor Author

!preview legacy-collections

@github-actions github-actions bot added the pr: preview This PR has a preview release label Sep 12, 2024
@github-actions github-actions bot added the pkg: example Related to an example package (scope) label Sep 13, 2024
@ascorbic ascorbic changed the title Add experimental support for emulating legacy collections using glob Emulate legacy collections using glob Sep 13, 2024
@github-actions github-actions bot added the pkg: integration Related to any renderer integration (scope) label Sep 16, 2024
@ascorbic ascorbic marked this pull request as ready for review September 16, 2024 13:44
@ascorbic
Copy link
Contributor Author

!preview legacy-collections

@ascorbic ascorbic changed the title Emulate legacy collections using glob Implement legacy collections using glob Sep 16, 2024
- The `layout` field is not supported in Markdown
- Experimental content collection cache is not supported
- Sort order of generated collections is non-deterministic and platform-dependent.
- `image().refine()` is not supported
Copy link
Member

Choose a reason for hiding this comment

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

Is this not supported in content layer in general?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. It's one of the things I missed. It'll be tough to do, because of the fact we don't transform it into an object until runtime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs pr pkg: astro Related to the core `astro` package (scope) pkg: example Related to an example package (scope) pkg: integration Related to any renderer integration (scope) pr: preview This PR has a preview release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants