-
-
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 using images in content collections (#6483)
* fix(images): Fix not being able to refer to images in content collections * fix(images): Normalize path * fix(images): Do it properly * chore: changeset
- Loading branch information
1 parent
7d1dd51
commit a9a6ae2
Showing
13 changed files
with
199 additions
and
62 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 | ||
--- | ||
|
||
Fix images defined in content collections schemas not working |
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
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
10 changes: 10 additions & 0 deletions
10
packages/astro/test/fixtures/core-image-ssg/src/content/blog/one.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,10 @@ | ||
--- | ||
title: One | ||
image: penguin2.jpg | ||
cover: | ||
image: penguin1.jpg | ||
--- | ||
|
||
# A post | ||
|
||
text here |
15 changes: 15 additions & 0 deletions
15
packages/astro/test/fixtures/core-image-ssg/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,15 @@ | ||
import { defineCollection, image, z } from "astro:content"; | ||
|
||
const blogCollection = defineCollection({ | ||
schema: z.object({ | ||
title: z.string(), | ||
image: image(), | ||
cover: z.object({ | ||
image: image() | ||
}) | ||
}), | ||
}); | ||
|
||
export const collections = { | ||
blog: blogCollection | ||
}; |
33 changes: 33 additions & 0 deletions
33
packages/astro/test/fixtures/core-image-ssg/src/pages/blog/[...slug].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,33 @@ | ||
--- | ||
import { getImage } from 'astro:assets'; | ||
import { getCollection } from 'astro:content'; | ||
export async function getStaticPaths() { | ||
const blogEntries = await getCollection('blog'); | ||
return blogEntries.map(entry => ({ | ||
params: { slug: entry.slug }, props: { entry }, | ||
})); | ||
} | ||
const { entry } = Astro.props; | ||
const { Content } = await entry.render(); | ||
const myImage = await getImage(entry.data.image); | ||
--- | ||
<html> | ||
<head> | ||
<title>Testing</title> | ||
</head> | ||
<body> | ||
<h1>Testing</h1> | ||
|
||
<div id="direct-image"> | ||
<img src={entry.data.image.src} width={entry.data.image.width} height={entry.data.image.height} /> | ||
</div> | ||
|
||
<div id="nested-image"> | ||
<img src={entry.data.cover.image.src} width={entry.data.cover.image.width} height={entry.data.cover.image.height} /> | ||
</div> | ||
|
||
<Content /> | ||
</body> | ||
</html> |
2 changes: 2 additions & 0 deletions
2
packages/astro/test/fixtures/core-image/src/content/blog/one.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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
--- | ||
title: One | ||
image: penguin2.jpg | ||
cover: | ||
image: penguin1.jpg | ||
--- | ||
|
||
# A post | ||
|
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.