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

前端 未结 4 1058
南旧
南旧 2021-02-15 16:10

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

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

The problem is I will ha

4条回答
  •  长发绾君心
    2021-02-15 17:01

    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

提交回复
热议问题