From 63141f3f3e4a57d2f55ccfebd7e506ea1033a1ab Mon Sep 17 00:00:00 2001 From: Erika <3019731+Princesseuh@users.noreply.github.com> Date: Fri, 22 Sep 2023 14:28:03 +0200 Subject: [PATCH] fix: properly generate code for multiple images in same markdown file (#8633) --- .changeset/mean-forks-ring.md | 5 +++++ 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 + 4 files changed, 11 insertions(+), 3 deletions(-) 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 000000000..1aa40a6b5 --- /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 diff --git a/packages/astro/src/vite-plugin-markdown/index.ts b/packages/astro/src/vite-plugin-markdown/index.ts index 7d4a97392..dfc0bc0e0 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 7a0a46822..a6ee4342c 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 98da01ce4..822ed6189 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