Skip to content

Commit

Permalink
fix: properly generate code for multiple images in same markdown file (
Browse files Browse the repository at this point in the history
  • Loading branch information
Princesseuh authored Sep 22, 2023
1 parent de7a7fb commit 63141f3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/mean-forks-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fix build not working when having multiple images in the same Markdown file
6 changes: 4 additions & 2 deletions packages/astro/src/vite-plugin-markdown/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/test/core-image.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions packages/astro/test/fixtures/core-image/src/pages/post.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
![My article cover](../assets/penguin1.jpg)
![My article cover](../assets/penguin2.jpg)

Image worked

0 comments on commit 63141f3

Please sign in to comment.