0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

fix: handle uppercase image file extensions (#12623)

This commit is contained in:
Matt Kane 2024-12-04 12:34:24 +00:00 committed by GitHub
parent 29bcdf5296
commit 0e4fecbb13
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 25 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Correctly handles images in content collections with uppercase file extensions

View file

@ -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;
}

View file

@ -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');

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

View file

@ -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.

View file

@ -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');
@ -49,6 +50,7 @@ export async function GET() {
yamlLoader,
tomlLoader,
nestedJsonLoader,
atlantis
})
);
}