Add support for directory-based collections #4116
Replies: 7 comments
-
|
I think this functionality would be great! I also have a scenario that would greatly benefit from this: I am using Jérôme Coupé's way of translating content, this means that I am using en/
- faq/
- - A.md
- - B.md
- - C.md
- - faq.11tydata.js
- index.html
- en.11tydata.js
de/
- faq/
- - A.md
- - B.md
- - C.md
- - faq.11tydata.js
- index.html
- de.11tydata.jsBut I realised that all of these pieces of content needed to be their own collection in order for me to access it as such. If they shared the tag The information about what faq's belong to where sits in eleventyComputed data, or in the directory structure. I found solutions to this issue thanks to @j-f1 's help in the 11ty Discord, but it would have been very intuitive, if we had something like local collections, based on folder structures. |
Beta Was this translation helpful? Give feedback.
-
|
I imagine this might be difficult to do in a way that works for everybody's specific file/directory structure. But given a directory structure like: src
├── blog/
│ ├── 2020/
│ │ └── one.md
│ ├── 2021/
│ │ ├── four.md
│ │ └── two.md
│ ├── 2022/
│ │ └── three.md
│ └── tips/
│ └── addplugin.md
└── index.liquidIt will try and make collections named "blog_2020", "blog_2021", "blog_2022", and "blog_tips" directories and create custom collections based on a rough Not sure of an easy way to use The repo also has a pagination file which will create www/blog/2020/index.html files with a listing of all the posts in that collection. |
Beta Was this translation helpful? Give feedback.
-
|
@nachtfunke I usually work with folder based collections for this king of setup using |
Beta Was this translation helpful? Give feedback.
-
|
@j-f1 Not sure if that would fit your exact use case, but I think my current take on this would probably be to build a EDIT: coming to think of it, maybe you could use the If you would like to paginate those filtered collection items, then you need another approach, which involves creating chunked collections. Here is a (somewhat old) repo using that approach. |
Beta Was this translation helpful? Give feedback.
-
Thank you @pdehaan 👏 |
Beta Was this translation helpful? Give feedback.
-
|
Automatically creating collections based on folders is a feature of Pack11ty, my Eleventy starter: I've been moving most features of Pack11ty into a plugin a few days ago, so that it can be added to any existing site: https://github.com/nhoizey/eleventy-plugin-pack11ty/ (Documentation is not yet fully up-to-date.) If you have a There are also automated collections for archives like |
Beta Was this translation helpful? Give feedback.
-
|
Cross-link to a nice approach described in #1230 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Is your feature request related to a problem? Please describe.
I have a bunch of pages categorized by year and season on my website. I then want to display all the files for a given season together on a single index page for each season.
Describe the solution you'd like
I would like a collection to be automatically created for each folder and subfolder in the input folder, and to have some sort of global data value listing all of those collections.
Maybe something like
collections["folder:scripts"],collections["folder:scripts/2020-2021"], andcollections["folder:scripts/2020-2021/fall"], plus a globalfoldersthat has a structure like this?…but I’m not super happy with that approach and I’m sure someone else can come up with a better one.
Describe alternatives you've considered
tagsto every page is annoying and repetitive, as there are a few hundred pages.tagswould similarly be quite repetitive.addCollectionin a loop to create each one.Beta Was this translation helpful? Give feedback.
All reactions