-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(astro): always return cloned content collection (#11228)
* fix: always return cloned content collection * Update .changeset/early-melons-thank.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> --------- Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
- Loading branch information
1 parent
28ee6e7
commit 1e293a1
Showing
12 changed files
with
139 additions
and
3 deletions.
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,5 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Updates `getCollection()` to always return a cloned array |
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
6 changes: 6 additions & 0 deletions
6
packages/astro/test/fixtures/content-collections-mutation/astro.config.mjs
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 mdx from '@astrojs/mdx'; | ||
import { defineConfig } from 'astro/config'; | ||
|
||
export default defineConfig({ | ||
integrations: [mdx()], | ||
}); |
9 changes: 9 additions & 0 deletions
9
packages/astro/test/fixtures/content-collections-mutation/package.json
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,9 @@ | ||
{ | ||
"name": "@test/content-collections-mutation", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"astro": "workspace:*", | ||
"@astrojs/mdx": "workspace:*" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...ages/astro/test/fixtures/content-collections-mutation/src/content/blog/first.md
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 @@ | ||
--- | ||
title: "First Blog" | ||
date: 2024-04-05 | ||
--- | ||
|
||
First blog content. |
6 changes: 6 additions & 0 deletions
6
...ges/astro/test/fixtures/content-collections-mutation/src/content/blog/second.md
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 @@ | ||
--- | ||
title: "Second Blog" | ||
date: 2024-04-06 | ||
--- | ||
|
||
Second blog content. |
6 changes: 6 additions & 0 deletions
6
...ages/astro/test/fixtures/content-collections-mutation/src/content/blog/third.md
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 @@ | ||
--- | ||
title: "Third Blog" | ||
date: 2024-04-07 | ||
--- | ||
|
||
Third blog content. |
16 changes: 16 additions & 0 deletions
16
packages/astro/test/fixtures/content-collections-mutation/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,16 @@ | ||
// 1. Import utilities from `astro:content` | ||
import { z, defineCollection } from "astro:content"; | ||
|
||
// 2. Define a `type` and `schema` for each collection | ||
const blogCollection = defineCollection({ | ||
type: "content", // v2.5.0 and later | ||
schema: z.object({ | ||
title: z.string(), | ||
date: z.date(), | ||
}), | ||
}); | ||
|
||
// 3. Export a single `collections` object to register your collection(s) | ||
export const collections = { | ||
blog: blogCollection, | ||
}; |
25 changes: 25 additions & 0 deletions
25
packages/astro/test/fixtures/content-collections-mutation/src/pages/another_page.astro
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,25 @@ | ||
--- | ||
import { getCollection } from "astro:content"; | ||
const blogs = await getCollection("blog"); | ||
blogs.sort((a, b) => b.data.date.valueOf() - a.data.date.valueOf()); // sort by date most recent first | ||
const latestBlog = blogs.splice(0, 1)[0]; // modifies the collection | ||
--- | ||
|
||
<html> | ||
<body> | ||
<a href="/">home</a> | ||
<h1>Latest Blog</h1> | ||
<h2>{latestBlog.data.title}</h2> | ||
<p>posted: {latestBlog.data.date.toLocaleString()}</p> | ||
<br /> | ||
<h2>Older blogs</h2> | ||
{ | ||
blogs.map((b) => ( | ||
<> | ||
<h3>{b.data.title}</h3> | ||
<p>posted: {b.data.date.toLocaleString()}</p> | ||
</> | ||
)) | ||
} | ||
</body> | ||
</html> |
25 changes: 25 additions & 0 deletions
25
packages/astro/test/fixtures/content-collections-mutation/src/pages/index.astro
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,25 @@ | ||
--- | ||
import { getCollection } from "astro:content"; | ||
const blogs = await getCollection("blog"); | ||
blogs.sort((a, b) => b.data.date.valueOf() - a.data.date.valueOf()); // sort by date most recent first | ||
const latestBlog = blogs.splice(0, 1)[0]; // modifies the collection | ||
--- | ||
|
||
<html> | ||
<body> | ||
<a href="/another_page">other page</a> | ||
<h1>Latest Blog</h1> | ||
<h2>{latestBlog.data.title}</h2> | ||
<p>posted: {latestBlog.data.date.toLocaleString()}</p> | ||
<br /> | ||
<h2>Older blogs</h2> | ||
{ | ||
blogs.map((b) => ( | ||
<> | ||
<h3>{b.data.title}</h3> | ||
<p>posted: {b.data.date.toLocaleString()}</p> | ||
</> | ||
)) | ||
} | ||
</body> | ||
</html> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.