-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
ascorbic
wants to merge
38
commits into
next
Choose a base branch
from
auto-glob
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
6cfa42d
feat: support pattern arrays with glob
ascorbic c2f48aa
wip
ascorbic dd20f95
Merge branch 'next' into auto-glob
ascorbic 0e9b54c
feat: emulate legacy content collections
ascorbic 1ff97b4
Fixes
ascorbic 305a756
Merge branch 'next' into auto-glob
ascorbic 9585b5a
Lint
ascorbic 181c950
Correctly handle legacy data
ascorbic f47c6ba
Fix tests
ascorbic b4f14ea
Merge branch 'next' into auto-glob
ascorbic 3967012
Switch flag handling
ascorbic 072dd7e
Fix warnings
ascorbic 75c7181
Add layout warning
ascorbic 9d371a1
Update fixtures
ascorbic 1a27f35
More tests!
ascorbic e14090a
Handle empty md files
ascorbic 77b7815
Merge branch 'next' into auto-glob
ascorbic bb15ef5
Lockfile
ascorbic e42c4b0
Dedupe name
ascorbic 8b7dc59
Handle data ID unslug
ascorbic ab7918a
Fix e2e
ascorbic 57127ff
Merge branch 'next' into auto-glob
ascorbic 5d1684e
Clean build
ascorbic 032ce4f
Clean builds in tests
ascorbic f48be22
Test fixes
ascorbic f337838
Fix test
ascorbic ec2fcb0
Fix typegen
ascorbic 0aebf32
Fix tests
ascorbic b0cb038
Merge branch 'next' into auto-glob
ascorbic 8f2e3fe
Fixture updates
ascorbic a7cccef
Test updates
ascorbic a030814
Update changeset
ascorbic 67a4253
Test
ascorbic e1b9491
Remove wait in test
ascorbic 5200a5d
Handle race condition
ascorbic 7add932
Merge branch 'next' into auto-glob
ascorbic 869dc3a
Lock
ascorbic 505b426
Merge branch 'next' into auto-glob
ascorbic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Implements legacy content and data collections using `glob()` loader | ||
|
||
:warning: **BREAKING CHANGE FOR LEGACY CONTENT COLLECTIONS** :warning: | ||
|
||
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. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { defineCollection } from 'astro:content'; | ||
|
||
export const collections = { | ||
docs: defineCollection({}) | ||
}; |
6 changes: 6 additions & 0 deletions
6
packages/astro/e2e/fixtures/content-collections/src/content/config.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { defineCollection } from "astro:content"; | ||
|
||
|
||
const posts = defineCollection({}); | ||
|
||
export const collections = { posts }; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.