Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sub-Collections or Sub-Categories in Jekyll

Tags:

jekyll

Is there a method built into Jekyll for forming categories and sub-categories, or collections and sub-collections?

For example:

├───linux
│   ├───desktops
│   └───shell
└───windows
    ├───desktop
    └───server

I'm currently using collections for "linux" and "windows", and can place an index.html page within each to create a browsable structure, however I would like to categorize posts further and programmatically display 'sub-categories', or 'sub-collections', on the website.

like image 602
Surprise Associate Avatar asked Oct 17 '25 02:10

Surprise Associate


1 Answers

I've been struggling with this need as well... no luck 😕.

However, I think I found a workaround that may help to keep the folder structure tidy. A combination of collections, naming convention, and permalink.

For example:

linux-main:
    output: true
    permalink: /linux/:title/

linux-desktop:
    output: true
    permalink: /linux/desktop/:title/

linux-shell:
    output: true
    permalink: /linux/shell/:title/

windows-main:
    output: true
    permalink: /windows/:title/

windows-desktop:
    output: true
    permalink: /windows/desktop/:title/

windows-shell:
    output: true
    permalink: /windows/shell/:title/

In the project structure this will look like this:

📦 Project
 ┣ 📂 linux-main
 ┃ ┣ 📝post1.md
 ┃ ┗ 📝post2.md
 ┣ 📂 linux-desktop
 ┃ ┣ 📝post1.md
 ┃ ┗ 📝post2.md
 ┣ 📂 linux-shell
 ┃ ┗ 📝post1.md
 ┣ 📂 windows-main
 ┣ 📂 windows-desktop
 ┗ 📂 windows-shell

And the _site folder will be:

📦 Project
 ┣ 📂 linux
 ┃ ┣ 📝post1.html
 ┃ ┣ 📝post2.html
 ┣ ┣ 📂 desktop
 ┃ ┃ ┣ 📝post1.html
 ┃ ┃ ┗ 📝post2.html
 ┣ ┗ 📂 shell
 ┃   ┗ 📝post1.html
 ┗ 📂 windows
   ┣ 📂 desktop
   ┗ 📂 shell
like image 102
Pizaranha Avatar answered Oct 19 '25 13:10

Pizaranha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!