Skip to content

Commit 0e4fecb

Browse files
authored
fix: handle uppercase image file extensions (#12623)
1 parent 29bcdf5 commit 0e4fecb

File tree

6 files changed

+25
-1
lines changed

6 files changed

+25
-1
lines changed

.changeset/six-toes-sort.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
Correctly handles images in content collections with uppercase file extensions

packages/astro/src/assets/utils/resolveImports.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export function imageSrcToImportId(imageSrc: string, filePath?: string): string
2020
return;
2121
}
2222
// We only care about images
23-
const ext = imageSrc.split('.').at(-1) as (typeof VALID_INPUT_FORMATS)[number] | undefined;
23+
const ext = imageSrc.split('.').at(-1)?.toLowerCase() as (typeof VALID_INPUT_FORMATS)[number] | undefined;
2424
if (!ext || !VALID_INPUT_FORMATS.includes(ext)) {
2525
return;
2626
}

packages/astro/test/content-layer.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,12 @@ describe('Content Layer', () => {
217217
assert.equal(json.entryWithReference.data.heroImage.format, 'jpg');
218218
});
219219

220+
it('loads images with uppercase extensions', async () => {
221+
assert.ok(json.atlantis.data.heroImage.src.startsWith('/_astro'));
222+
assert.ok(json.atlantis.data.heroImage.src.endsWith('.JPG'));
223+
assert.equal(json.atlantis.data.heroImage.format, 'jpg');
224+
});
225+
220226
it('loads images from custom loaders', async () => {
221227
assert.ok(json.images[0].data.image.src.startsWith('/_astro'));
222228
assert.equal(json.images[0].data.image.format, 'jpg');
45.9 KB
Loading
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
title: Atlantis
3+
description: 'Learn about the Atlantis NASA space shuttle.'
4+
publishedDate: 'Sat May 21 2022 00:00:00 GMT-0400 (Eastern Daylight Time)'
5+
tags: [space, 90s]
6+
heroImage: "./atlantis.JPG"
7+
---
8+
9+
**Source:** [Wikipedia](https://en.wikipedia.org/wiki/Space_Shuttle_Atlantis)
10+
11+
Space Shuttle Atlantis (Orbiter Vehicle Designation: OV-104) is a Space Shuttle orbiter vehicle belonging to the National Aeronautics and Space Administration (NASA), the spaceflight and space exploration agency of the United States. Constructed by the Rockwell International company in Southern California and delivered to the Kennedy Space Center in Eastern Florida in April 1985, Atlantis is the fourth operational and the second-to-last Space Shuttle built. Its maiden flight was STS-51-J from 3 to 7 October 1985.

packages/astro/test/fixtures/content-layer/src/pages/collections.json.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export async function GET() {
1212
const simpleLoader = await getCollection('cats');
1313

1414
const entryWithReference = await getEntry('spacecraft', 'columbia-copy');
15+
const atlantis = await getEntry('spacecraft', 'atlantis');
1516
const referencedEntry = await getEntry(entryWithReference.data.cat);
1617

1718
const entryWithImagePath = await getEntry('spacecraft', 'lunar-module');
@@ -49,6 +50,7 @@ export async function GET() {
4950
yamlLoader,
5051
tomlLoader,
5152
nestedJsonLoader,
53+
atlantis
5254
})
5355
);
5456
}

0 commit comments

Comments
 (0)