Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle uppercase image file extensions #12623

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
})
);
}
Loading