withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
46.27k stars 2.44k forks source link

With Content Layer API, fsPath is no longer part of schema image data object #12155

Closed anarion80 closed 1 week ago

anarion80 commented 1 week ago

Astro Info

Astro                    v4.15.9
Node                     v20.10.0
System                   Windows (x64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             @astrojs/react
                         @astrojs/sitemap
                         astro-dynamic-import
                         auto-import
                         @astrojs/mdx
                         astro-icon

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

No response

Describe the Bug

Essentially the same as https://github.com/withastro/astro/issues/12136

With a collection defined using Content Layer loader:

const blog = defineCollection({
  loader: glob({ pattern: '**/*.md*', base: './src/data/blog' }),
  schema: ({ image }: SchemaContext) =>
    z.object({
      heroImage: image().or(z.string()),
    }),
});

the resulting heroImage object does not have fsPath like previously with content collections:

{
  src: '/_astro/image.Duq8VBCM.png',
  width: 29,
  height: 29,
  format: 'png'
}

I have the same situation with Astro 4.15.9 using experimental flag for contentLayer or using 5.0 beta without the experimental flag.

Minimal reproduction shows the console dump for the image.

What's the expected result?

fsPath is still there"

{
  src: '/_astro/image.Duq8VBCM.png',
  width: 1920,
  height: 1080,
  format: 'jpg',
  fsPath: '/fs/repo/path/src/content/blog/_images/test/image.png'
}

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-ngcwe1?file=src%2Fpages%2Findex.astro

Participation

Princesseuh commented 1 week ago

fsPath was intentionally never added to types or documented, as it was always intended to be an internal detail more than an actual API. What is your use case with it?

anarion80 commented 1 week ago

Accessing the file to darken it and blur and then use as background for og image generation.

My current workaround is use the src which is available like this:

originalImagePath = `dist${page.heroImage.src}`;