diff --git a/.changeset/six-toes-sort.md b/.changeset/six-toes-sort.md new file mode 100644 index 000000000000..3124986c512e --- /dev/null +++ b/.changeset/six-toes-sort.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Correctly handles images in content collections with uppercase file extensions diff --git a/packages/astro/src/assets/utils/resolveImports.ts b/packages/astro/src/assets/utils/resolveImports.ts index 53cd69f0addc..c3608084e729 100644 --- a/packages/astro/src/assets/utils/resolveImports.ts +++ b/packages/astro/src/assets/utils/resolveImports.ts @@ -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; } diff --git a/packages/astro/test/content-layer.test.js b/packages/astro/test/content-layer.test.js index 73375b185312..41d2f0fce692 100644 --- a/packages/astro/test/content-layer.test.js +++ b/packages/astro/test/content-layer.test.js @@ -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'); diff --git a/packages/astro/test/fixtures/content-layer/src/content/space/atlantis.JPG b/packages/astro/test/fixtures/content-layer/src/content/space/atlantis.JPG new file mode 100644 index 000000000000..8468822f8eaa Binary files /dev/null and b/packages/astro/test/fixtures/content-layer/src/content/space/atlantis.JPG differ diff --git a/packages/astro/test/fixtures/content-layer/src/content/space/atlantis.md b/packages/astro/test/fixtures/content-layer/src/content/space/atlantis.md new file mode 100644 index 000000000000..81f4352da179 --- /dev/null +++ b/packages/astro/test/fixtures/content-layer/src/content/space/atlantis.md @@ -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. diff --git a/packages/astro/test/fixtures/content-layer/src/pages/collections.json.js b/packages/astro/test/fixtures/content-layer/src/pages/collections.json.js index 5467550d70bb..968dfc24d3c6 100644 --- a/packages/astro/test/fixtures/content-layer/src/pages/collections.json.js +++ b/packages/astro/test/fixtures/content-layer/src/pages/collections.json.js @@ -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 }) ); }