Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image In Post Body Cannot Displayed #56

Open
NinjaGeekDev opened this issue Jan 23, 2024 · 6 comments
Open

Image In Post Body Cannot Displayed #56

NinjaGeekDev opened this issue Jan 23, 2024 · 6 comments

Comments

@NinjaGeekDev
Copy link

Hi,
I've found that each post's hero image is displayed correctly because it's defined in the MDX frontmatter section and is built to the /dist/_astro path during the Astro build stage. Unfortunately, however, the image files referenced in the MDX body are not built to that path, which results in the images in the body not being displayed. This might be a silly question to ask, but I'm a complete beginner, could you please help me out? Thank you!

image
@serjs
Copy link

serjs commented Jan 30, 2024

+1 Today notice this issue too. With same image path, adding images through tinacms. HeroImage available from _astro folder at the same time

@FahimFBA
Copy link

FahimFBA commented Feb 1, 2024

I am also facing this exact issue. Therefore, I am trying to change the theme entirely.

@serjs
Copy link

serjs commented Feb 1, 2024

I read astro docs about image optimization and TinaCMS docs. Looks like there are no way to fix thus out of box. Every image in mdx must have path under src folder. In this template case, there where images mentioned ../../../src/assets/images must be placed instead /src/assets/images inserted by Tina. Correct path handled by Astro during build (image optimisation process).

We can add prebuild step with recursive find all mdx files and using sed regex rule to preprocess all images during build, but I thing it's better doing in JS, not system shell comands for exclude OS, shell differences.

@WDI-Json
Copy link

WDI-Json commented Feb 3, 2024

Based on @serjs I've discovered a workaround which is easy enough if you're okay with it:

---
myfields
---

import { Image } from 'astro:assets'
import image1 from '/src/assets/images/image1.png'

<Image
	src={image1}
	alt='alttext'
/>

After many attempts, this was the easiest way to work around this problem. May it serve you well.

@Brian-Kariu
Copy link

Fixed this by moving from Sharp image server to Sqoosh.
link to astro docs

import { defineConfig, squooshImageService } from 'astro/config';

export default defineConfig({
  image: {
    service: squooshImageService(),
  },
});

@NongBritee
Copy link

facing same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants