withastro/astro

Images in Content Collections are not worked in Astro v5

Opened this issue · 0 comments

Astro Info

Astro                    v5.0.9
Node                     v20.12.0
System                   macOS (arm64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             @astrojs/mdx
                         @astrojs/sitemap

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

From v5, I can no longer access images placed in the same folder as mdx files in Content Collections.

Here is the usage from the official documentation:

I have created a sample here.
https://github.com/psephopaiktes/astro-images-in-content-collections

Most of it remains the same as the official blog sample for each version, but I have changed the following files:

  • /src/content/config.ts (in v5, it's /src/content.config.ts)
  • Directory structure for blog images
  • Frontmatter of blog Markdown

In v4, it works fine as per the documentation, but in v5, the images either return a 404 error or the following error occurs:

A getStaticPaths() route pattern was matched, but no matching static path was found for requested path /blog/first-post/[object%20Object]

The reason I want this structure is that I want to place the images for each blog post in the same folder as the post mdx file.

Bad:

  • src/content/blog/first-post.md
  • src/public/img/first-post-cover.jpg

Good:

  • src/content/blog/first-post/index.md
  • src/content/blog/first-post/cover.md

What's the expected result?

Images placed in the same location as the .md file should be handled as Content Collections without errors.

If there is another solution to place images in the same folder, that would be OK to me.

Link to Minimal Reproducible Example

https://github.com/psephopaiktes/astro-images-in-content-collections

Participation

  • I am willing to submit a pull request for this issue.