Skip to content

Commit

Permalink
fix: handle uppercase image file extensions (#12623)
Browse files Browse the repository at this point in the history
  • Loading branch information
ascorbic authored Dec 4, 2024
1 parent 29bcdf5 commit 0e4fecb
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/six-toes-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Correctly handles images in content collections with uppercase file extensions
2 changes: 1 addition & 1 deletion packages/astro/src/assets/utils/resolveImports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function imageSrcToImportId(imageSrc: string, filePath?: string): string
return;
}
// We only care about images
const ext = imageSrc.split('.').at(-1) as (typeof VALID_INPUT_FORMATS)[number] | undefined;
const ext = imageSrc.split('.').at(-1)?.toLowerCase() as (typeof VALID_INPUT_FORMATS)[number] | undefined;
if (!ext || !VALID_INPUT_FORMATS.includes(ext)) {
return;
}
Expand Down
6 changes: 6 additions & 0 deletions packages/astro/test/content-layer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ describe('Content Layer', () => {
assert.equal(json.entryWithReference.data.heroImage.format, 'jpg');
});

it('loads images with uppercase extensions', async () => {
assert.ok(json.atlantis.data.heroImage.src.startsWith('/_astro'));
assert.ok(json.atlantis.data.heroImage.src.endsWith('.JPG'));
assert.equal(json.atlantis.data.heroImage.format, 'jpg');
});

it('loads images from custom loaders', async () => {
assert.ok(json.images[0].data.image.src.startsWith('/_astro'));
assert.equal(json.images[0].data.image.format, 'jpg');
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
title: Atlantis
description: 'Learn about the Atlantis NASA space shuttle.'
publishedDate: 'Sat May 21 2022 00:00:00 GMT-0400 (Eastern Daylight Time)'
tags: [space, 90s]
heroImage: "./atlantis.JPG"
---

**Source:** [Wikipedia](https://en.wikipedia.org/wiki/Space_Shuttle_Atlantis)

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.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export async function GET() {
const simpleLoader = await getCollection('cats');

const entryWithReference = await getEntry('spacecraft', 'columbia-copy');
const atlantis = await getEntry('spacecraft', 'atlantis');
const referencedEntry = await getEntry(entryWithReference.data.cat);

const entryWithImagePath = await getEntry('spacecraft', 'lunar-module');
Expand Down Expand Up @@ -49,6 +50,7 @@ export async function GET() {
yamlLoader,
tomlLoader,
nestedJsonLoader,
atlantis
})
);
}

0 comments on commit 0e4fecb

Please sign in to comment.