3

I created a custom collection in my Jekyll configuration:

collections: tutorials: output: true permalink: /tutorials/:path/ 

I have a markdown file with the path: _tutorial/category/ios.md I also have an image with the path: _tutorial/category/xcode.png

In ios.md I use: ![xcode](xcode.png)

Which should make sense since they are on the same directory.

In the _site generated folder, I see

tutorial/ category/ xcode.png ios/ index.html 

So obviously the generated HTML is looking at the wrong place for the image since they are no longer in the same directory.

I thought of changing my structure to have my markdown file be _tutorial/category/ios/index.md, however all it did was create a folder called index so the problem is the same.

What is the expected way to include images in Jekyll/Markdown?

Am I supposed to keep them all in a folder at the root of the site? That would obviously work but it makes it hard to keep track of which images are associated with each post...

8
  • Does it work if you have ios.md and ios/xcode.png? Commented Oct 20, 2015 at 13:46
  • Good idea, seems to work. A bit counterintuitive, nor natural... My other workaround is to use ![xcode](../xcode.png). But I am wondering what's the best practice too. Commented Oct 20, 2015 at 13:50
  • The best practice is most likely keeping images in one /assets folder as mentioned in the docs. You can organize your site in a way that makes sense to you. I have images in the same folders as their pages, and I haven't run into this problem because I use .html pages (Jekyll doesn't auto-create the folder + index.html for nice links in that case). Commented Oct 20, 2015 at 13:53
  • Can I write markdown in file with .html extensions? Commented Oct 20, 2015 at 13:54
  • Probably... in your layout you could do {{ content | markdownify }}. I haven't tried this. Commented Oct 20, 2015 at 14:11

1 Answer 1

3

Because your collection has a permalink ending with a slash:

permalink: /tutorials/:path/ 

Jekyll will turn your Markdown file into an index.html file to make the link pretty. So ios.md becomes ios/index.html.

You can dodge this issue entirely by using links with extensions. This is the default option. Note there's no trailing slash:

permalink: /tutorials/:path 

If you still want extension-free links, then for the relative image paths to work, you can either move the Markdown up one directory:

ios.md ios/ xcode.png 

or change the image path to ![xcode](../xcode.png). Both approaches seem counter-intuitive.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.