fix: properly generate code for multiple images in same markdown file (#8633)

This commit is contained in:
Erika 2023-09-22 14:28:03 +02:00 committed by GitHub
parent de7a7fbdc3
commit 63141f3f3e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 3 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fix build not working when having multiple images in the same Markdown file

View file

@ -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')}
}
}

View file

@ -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(

View file

@ -1,3 +1,4 @@
![My article cover](../assets/penguin1.jpg)
![My article cover](../assets/penguin2.jpg)
Image worked