Home Jekyll PostFiles
Post
Cancel

Jekyll PostFiles

So a really annoying thing with this site is that you have to put all your images for a post in a separate folder structure and then reference them from that folder.

Here’s an example Imagine you have these files:

1
2
3
4
5
6
7
8
_posts/
  2016-06/
    2016-06-09-so-long-cloudflare-and-thanks-for-all-the-fissh.md
…
assets/
  2016-06-09-cloudflare/
    cloudflare-architecture.png
    performance-report-sample.pdf

Using the post’s Markdown you have to write this.

1
2
3
4
5
6
7
8
9
10
11
12
13
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.

![Cloudflare architecture](/assets/2016-06-09-cloudflare/cloudflare-architecture.png)

Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat.

Here is [an example of performance report](/assets/2016-06-09-cloudflare/performance-report-sample.pdf).

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.

It gets really annoying.

Any way there’s a better way.

All you need to do is to add this to your Gemfile and then build it. If you’re like me it’s taken care of with the CI/CD

1
2
3
group :jekyll_plugins do
  gem 'jekyll-postfiles'
end

From there you can just create a folder for the post add the file.md and the rest of the images and reference them by filename. No more writing relative file paths!!!

Here’s an example.

File Structure

1
2
3
2023-03-09-jekyll-postfiles/
    2023-03-09-jekyll-postfiles.md
    test.jpg

MD file

1
2
3
Some random text

![An image](test.jpg)
This post is licensed under CC BY 4.0 by the author.
Trending Tags