JoshBl_
JoshBl_

Reputation: 51

Jekyll - Trying to add images to a post but Jekyll cannot find them

I'm trying to add images to a post but whenever I try to view them in a post (running Jekyll using the 'bundle exec jekyll serve --draft' option when viewing locally) - Jekyll prints the following in the Terminal:

[2019-10-27 20:38:06] ERROR `/blog/jekyll/update/2019/10/_site/assets/ruby_on_rails_image1.jpg' not found.

I'm using the following in my markdown file to add the image to a post:

![Ruby on Rails AWS](../_site/assets/ruby_on_rails_image1.jpg)

I can open the image in Visual Studio Code so I know that the path to the image is correct but for whatever reason, Jekyll can't find it. I've tried viewing the image individually

Does anyone know what I'm doing wrong?

Thanks!

Upvotes: 0

Views: 767

Answers (1)

DC.Azndj
DC.Azndj

Reputation: 1396

The ../ and _site are causing the issue. Basically, you're telling Jekyll to find the image url in the files after being processed by Jekyll (_site) and where to start looking relative to the blog post (../). To fix, just remove the .. so that the url is ![Ruby on Rails AWS](/_site/assets/ruby_on_rails_image1.jpg)

HOWEVER, relying on the image url after Jekyll processing is not a good idea. Rather, you can tell Jekyll where the image is before processing. Jekyll keeps track of the image and the image's final url. Then it uses that url to get the image. This way you don't care about how Jekyll processes stuff. You can rely on your repo's current structure instead of the structure after processing.

To do that, use the Jekyll link tag: ![Ruby on Rails AWS]({% link path/to/ruby_on_rails_image1.jpg %})

Docs on link tag

Upvotes: 1

Related Questions