From 4df3b22f09742af3c31986bbb043b7a56f930daf Mon Sep 17 00:00:00 2001 From: Princesseuh Date: Fri, 22 Sep 2023 12:21:42 +0200 Subject: [PATCH 1/2] fix: properly generate code for multiple images in same markdown file --- packages/astro/src/vite-plugin-markdown/index.ts | 6 ++++-- packages/astro/test/core-image.test.js | 2 +- packages/astro/test/fixtures/core-image/src/pages/post.md | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/astro/src/vite-plugin-markdown/index.ts b/packages/astro/src/vite-plugin-markdown/index.ts index 7d4a97392fdd..dfc0bc0e0d92 100644 --- a/packages/astro/src/vite-plugin-markdown/index.ts +++ b/packages/astro/src/vite-plugin-markdown/index.ts @@ -120,13 +120,15 @@ export default function markdown({ settings, logger }: AstroPluginOptions): Plug ${layout ? `import Layout from ${JSON.stringify(layout)};` : ''} import { getImage } from "astro:assets"; - ${imagePaths.map((entry) => `import Astro__${entry.safeName} from ${JSON.stringify(entry.raw)};`)} + ${imagePaths + .map((entry) => `import Astro__${entry.safeName} from ${JSON.stringify(entry.raw)};`) + .join('\n')} const images = async function() { return { ${imagePaths .map((entry) => `"${entry.raw}": await getImage({src: Astro__${entry.safeName}})`) - .join('\n')} + .join(',\n')} } } diff --git a/packages/astro/test/core-image.test.js b/packages/astro/test/core-image.test.js index 7a0a468225bf..a6ee4342cf3f 100644 --- a/packages/astro/test/core-image.test.js +++ b/packages/astro/test/core-image.test.js @@ -310,7 +310,7 @@ describe('astro:image', () => { it('Adds the tag', () => { let $img = $('img'); - expect($img).to.have.a.lengthOf(1); + expect($img).to.have.a.lengthOf(2); // Verbose test for the full URL to make sure the image went through the full pipeline expect( diff --git a/packages/astro/test/fixtures/core-image/src/pages/post.md b/packages/astro/test/fixtures/core-image/src/pages/post.md index 98da01ce41b2..822ed61899a7 100644 --- a/packages/astro/test/fixtures/core-image/src/pages/post.md +++ b/packages/astro/test/fixtures/core-image/src/pages/post.md @@ -1,3 +1,4 @@ ![My article cover](../assets/penguin1.jpg) +![My article cover](../assets/penguin2.jpg) Image worked From 6e1bec08adff2b1b76a87885a7fb6579acef3bc2 Mon Sep 17 00:00:00 2001 From: Princesseuh Date: Fri, 22 Sep 2023 12:29:55 +0200 Subject: [PATCH 2/2] chore: changese --- .changeset/mean-forks-ring.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/mean-forks-ring.md diff --git a/.changeset/mean-forks-ring.md b/.changeset/mean-forks-ring.md new file mode 100644 index 000000000000..1aa40a6b554a --- /dev/null +++ b/.changeset/mean-forks-ring.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix build not working when having multiple images in the same Markdown file