Include images in Jekyll collection

I have custom collections for my Jekyll project:

collections_dir: events
    output: true
    permalink: /:collection/:title
    sort_by: date
    output: true
    permalink: /:collection/:title
    sort_by: date

And it’s my directory structure:

├── _config.yml
└── events
    ├── _event1
    │   ├── images
    │   │   ├── title1.jpg
    │   │   └── title2.jpg
    │   ├──
    │   └──
    └── _event2
        ├── images
        │   ├── title3.jpg
        │   └── title4.jpg
  • I have two events collection
  • Every collection has some docs
  • Every doc needs an image


Currently, I should manually put all images in the assets folder so I can use them like this /assets/img/event1/title1.jpg :

├── _config.yml
├── events
└── assets
    └── img
        └── event1
            ├── title1.jpg
            ├── title2.jpg
            ├── ...
            └── ...

It’s very hard to manage image assets for every collection because I have many of them. Is there any solution that every collection has its own asset folder ( Like the first directory tree ) and Jekyll’s build process copies them in the final _site directory?

Unfortunately, this doesn’t work. Jekyll will pick one image of every extension from every collection, rename it to the collection’s name ( event1.jpg / event1.png ) and copy that to the site’s root and return an error message for other ones:

Conflict: The following destination is shared by multiple files.
          The written file may end up with unexpected contents.
           - /<project>/events/_event1/images/title2.jpg
           - /<project>/events/_event1/images/title3.jpg
           - /<project>/events/_event1/images/title4.jpg

I don’t understand this behavior. Do you have any idea how to do this?

hmm, thats sounds weird, I think it could work.

This post seems to show what you want working (I think)- answer at the bottom:

If you were not using collections I think this works - ie - jekyll copies static files to the same location in the _site folder. You could use front matter variables to loop thru things though collections is simpler and less cpu intense.

hmm, that is your question lol. Did you see that answer? did it not work?