-
-
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 optimized images with
base
(#6643)
* fix(images): Fix images having the wrong path when using `base` * test(images): Add test for using images with base * test: add more tests * chore: changeset * fix: paths * refactor: feedback
- Loading branch information
1 parent
25cd3e5
commit fc0ed9c
Showing
19 changed files
with
232 additions
and
8 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 not having the proper path when using `base` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "@test/core-image-ssg", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"astro": "workspace:*" | ||
}, | ||
"exports": { | ||
"./service": "./src/service.ts" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions
10
packages/astro/test/fixtures/core-image-base/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: ~/assets/penguin2.jpg | ||
cover: | ||
image: ../../assets/penguin1.jpg | ||
--- | ||
|
||
# A post | ||
|
||
text here |
15 changes: 15 additions & 0 deletions
15
packages/astro/test/fixtures/core-image-base/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 | ||
}; |
5 changes: 5 additions & 0 deletions
5
packages/astro/test/fixtures/core-image-base/src/pages/alias.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,5 @@ | ||
--- | ||
import image from "~/assets/penguin1.jpg"; | ||
--- | ||
|
||
<img src={image.src} width={image.width} height={image.height} alt="A penguin!" /> |
3 changes: 3 additions & 0 deletions
3
packages/astro/test/fixtures/core-image-base/src/pages/aliasMarkdown.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,3 @@ | ||
![A penguin](~/assets/penguin1.jpg) | ||
|
||
A penguin |
33 changes: 33 additions & 0 deletions
33
packages/astro/test/fixtures/core-image-base/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> |
5 changes: 5 additions & 0 deletions
5
packages/astro/test/fixtures/core-image-base/src/pages/direct.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,5 @@ | ||
--- | ||
import image from "~/assets/penguin1.jpg"; | ||
--- | ||
|
||
<img src={image.src} width={image.width} height={image.height} alt="A penguin!" /> |
18 changes: 18 additions & 0 deletions
18
packages/astro/test/fixtures/core-image-base/src/pages/format.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,18 @@ | ||
--- | ||
import { Image } from 'astro:assets'; | ||
import myImage from "../assets/penguin1.jpg"; | ||
--- | ||
<html> | ||
<head> | ||
|
||
</head> | ||
<body> | ||
<div id="no-format"> | ||
<Image src={myImage} alt="a penguin" /> | ||
</div> | ||
|
||
<div id="format-avif"> | ||
<Image src={myImage} alt="a penguin" format="avif" /> | ||
</div> | ||
</body> | ||
</html> |
8 changes: 8 additions & 0 deletions
8
packages/astro/test/fixtures/core-image-base/src/pages/get-image.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,8 @@ | ||
--- | ||
import { getImage } from "astro:assets"; | ||
import image from "../assets/penguin2.jpg"; | ||
const myImage = await getImage({ src: image, width: 207, height: 243, alt: 'a penguin' }); | ||
--- | ||
|
||
<img src={myImage.src} {...myImage.attributes} /> |
18 changes: 18 additions & 0 deletions
18
packages/astro/test/fixtures/core-image-base/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,18 @@ | ||
--- | ||
import { Image } from 'astro:assets'; | ||
import myImage from "../assets/penguin1.jpg"; | ||
--- | ||
<html> | ||
<head> | ||
|
||
</head> | ||
<body> | ||
<div id="local"> | ||
<Image src={myImage} alt="a penguin" /> | ||
</div> | ||
|
||
<div id="remote"> | ||
<Image src="https://avatars.githubusercontent.com/u/622227?s=64" alt="fred" width="48" height="48" /> | ||
</div> | ||
</body> | ||
</html> |
3 changes: 3 additions & 0 deletions
3
packages/astro/test/fixtures/core-image-base/src/pages/post.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,3 @@ | ||
![My article cover](../assets/penguin1.jpg) | ||
|
||
Image worked |
22 changes: 22 additions & 0 deletions
22
packages/astro/test/fixtures/core-image-base/src/pages/quality.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,22 @@ | ||
--- | ||
import { Image } from 'astro:assets'; | ||
import myImage from "../assets/penguin1.jpg"; | ||
--- | ||
<html> | ||
<head> | ||
|
||
</head> | ||
<body> | ||
<div id="no-quality"> | ||
<Image src={myImage} alt="a penguin" /> | ||
</div> | ||
|
||
<div id="quality-low"> | ||
<Image src={myImage} alt="a penguin" quality="low" /> | ||
</div> | ||
|
||
<div id="quality-num"> | ||
<Image src={myImage} alt="a penguin" quality="70" /> | ||
</div> | ||
</body> | ||
</html> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.