In Jekyll, is it possible to group multiple collections inside the same folder?

In config.yml, I define my collections as follows:

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

The problem is that I will have many collections and they will clutter up my Jekyll root folder.

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

So, I would:

 _collections _dancing _music .... 
+7
source share
4 answers

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

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

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

collections_dir: [your_folder_here] will tell Jekyll to look into this collection folder. My folder structure in development is as follows:

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

And on the compiled site it looks like this:

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

One thing was also not set, but I found it useful, that you could display different collections in the same folder . In my case, I had a client site that had two types of working samples: client and general examples. We wanted to separate them for better service, but also show them in one folder. To do this, you can simply define a permalink for the collection. In our case, we put permalink for cases in the work folder ( permalink: /work/:name ).

Hope this helps!

It is also present in the Jekyll documentation

+4
source

The answer is no. Your collections folder should be at the root of your root folder.

Even if you say you create a collection in the _collections / _music folder and configure it like this:

 collections: collections/_music folder: output: true 

Jekyll finishes searching for your collection in the _collections_music folder (no slash) due to the path disinfection process.

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

+3
source

Nothing prevents you from using subfolders in your collection. (Note: this is not the answer to your question, but a possible workaround)

Thus, as a workaround, you can have only one collection: for example, _arts and organize your folders as follows:

 _arts dancing music concerts ..... 

to list them separately, you can use:

  1. the FrontMatter variable in your category: dancing files when you have an output, and check this, for example, for a dance-only list.

     {% for project in site.arts %} {% if project.category == 'dancing' %} .... {% endif %} {% endfor %} 
  2. or check the path when you have no output for the collection

     {% for project in site.arts %} {% if project.url contains 'dancing' %} .... {% endif %} {% endfor %} 

This can slow down your build if you have hundreds and hundreds of items inside.

+1
source

Now it is possible, since this issue has been combined.

The user is configured as:

 collections_dir: my_collections 

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

0
source

All Articles