Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Jekyll, can we group multiple collections inside the same folder?

In config.yml, I define my collections like this:

collections:
  music:
    output: false
  dancing:
    output: false

The problem is I will have lots of collections and they will clutter my root Jekyll folder.

Is there a way to group all the collections into a folder, named for example, _collections?

So, I would have:

_collections
     _dancing
     _music
     ....
like image 281
Dany D Avatar asked Apr 25 '16 21:04

Dany D


3 Answers

This is now possible (I'm running Jekyll 3.7.2, I'm not sure in which version this was implemented).

Here's how to do it: In your _config.yml you can define your collections as well as the folder for your collections. Let's take a look at an example on a client site I'm working on:

collections:
  events:
    output: true
  work:
    output: true
  jobs:
    output: true
  cases:
    output: true
    permalink: /work/:name
collections_dir: pages

The collections_dir: [your_folder_here] will tell Jekyll to look into that folder for collections. My folder structure in development is as follows:

pages/
  ...
  _events/
  _work/
  _jobs/
  _cases/

And in the compiled site it's as follows:

...
events/
jobs/
work/ (contains both "work" and "cases" collections)

One thing also that wasn't asked, but I found to be useful, was that you're able to output different collections into a same folder. In my case I had a client website on which there were two types of work samples: client cases and general examples. We wanted to separate them for better maintenance but also show them in the same folder. To achieve this you can simply define a permalink for the collection. In our case we put permalink for the cases to appear in the work folder (permalink: /work/:name).

Hope this helps!

This is also present in the Jekyll documentation

like image 190
Jussi Virtanen Avatar answered Nov 15 '22 05:11

Jussi Virtanen


Answer is no. Your collections folder must be at the root of your root folder.

Even if you name you create a collection in _collections/_music folder, and set it up like this :

collections:

  collections/_music folder:
    output: true

Jekyll ends up looking for your collection in _collections_music folder (without any slash) because of path sanitize process.

See jekyll code in collection.rb, site.rb and jekyll.rb

like image 23
David Jacquel Avatar answered Nov 15 '22 05:11

David Jacquel


This is now possible since this issue was merged.

User configures as:

collections_dir: my_collections

Then we look in my_collections/_pizza for the pizza collection, and my_collections/_lasagna for the lasagna collection.

like image 28
simonwo Avatar answered Nov 15 '22 03:11

simonwo