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:
parent
29bcdf5296
commit
0e4fecbb13
6 changed files with 25 additions and 1 deletions
5
.changeset/six-toes-sort.md
Normal file
5
.changeset/six-toes-sort.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Correctly handles images in content collections with uppercase file extensions
|
|
@ -20,7 +20,7 @@ export function imageSrcToImportId(imageSrc: string, filePath?: string): string
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// We only care about images
|
// 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)) {
|
if (!ext || !VALID_INPUT_FORMATS.includes(ext)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -217,6 +217,12 @@ describe('Content Layer', () => {
|
||||||
assert.equal(json.entryWithReference.data.heroImage.format, 'jpg');
|
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 () => {
|
it('loads images from custom loaders', async () => {
|
||||||
assert.ok(json.images[0].data.image.src.startsWith('/_astro'));
|
assert.ok(json.images[0].data.image.src.startsWith('/_astro'));
|
||||||
assert.equal(json.images[0].data.image.format, 'jpg');
|
assert.equal(json.images[0].data.image.format, 'jpg');
|
||||||
|
|
BIN
packages/astro/test/fixtures/content-layer/src/content/space/atlantis.JPG
vendored
Normal file
BIN
packages/astro/test/fixtures/content-layer/src/content/space/atlantis.JPG
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 46 KiB |
11
packages/astro/test/fixtures/content-layer/src/content/space/atlantis.md
vendored
Normal file
11
packages/astro/test/fixtures/content-layer/src/content/space/atlantis.md
vendored
Normal 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.
|
|
@ -12,6 +12,7 @@ export async function GET() {
|
||||||
const simpleLoader = await getCollection('cats');
|
const simpleLoader = await getCollection('cats');
|
||||||
|
|
||||||
const entryWithReference = await getEntry('spacecraft', 'columbia-copy');
|
const entryWithReference = await getEntry('spacecraft', 'columbia-copy');
|
||||||
|
const atlantis = await getEntry('spacecraft', 'atlantis');
|
||||||
const referencedEntry = await getEntry(entryWithReference.data.cat);
|
const referencedEntry = await getEntry(entryWithReference.data.cat);
|
||||||
|
|
||||||
const entryWithImagePath = await getEntry('spacecraft', 'lunar-module');
|
const entryWithImagePath = await getEntry('spacecraft', 'lunar-module');
|
||||||
|
@ -49,6 +50,7 @@ export async function GET() {
|
||||||
yamlLoader,
|
yamlLoader,
|
||||||
tomlLoader,
|
tomlLoader,
|
||||||
nestedJsonLoader,
|
nestedJsonLoader,
|
||||||
|
atlantis
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue