diff options
author | 2023-09-22 14:28:03 +0200 | |
---|---|---|
committer | 2023-09-22 14:28:03 +0200 | |
commit | 63141f3f3e4a57d2f55ccfebd7e506ea1033a1ab (patch) | |
tree | d664884a1b25153046771500eaac0a5a69a67953 | |
parent | de7a7fbdc37631cefc70e2310ac9ae286ec7ba32 (diff) | |
download | astro-63141f3f3e4a57d2f55ccfebd7e506ea1033a1ab.tar.gz astro-63141f3f3e4a57d2f55ccfebd7e506ea1033a1ab.tar.zst astro-63141f3f3e4a57d2f55ccfebd7e506ea1033a1ab.zip |
fix: properly generate code for multiple images in same markdown file (#8633)
-rw-r--r-- | .changeset/mean-forks-ring.md | 5 | ||||
-rw-r--r-- | packages/astro/src/vite-plugin-markdown/index.ts | 6 | ||||
-rw-r--r-- | packages/astro/test/core-image.test.js | 2 | ||||
-rw-r--r-- | packages/astro/test/fixtures/core-image/src/pages/post.md | 1 |
4 files changed, 11 insertions, 3 deletions
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 <img> 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 @@  + Image worked |