11ty / eleventy

A simpler site generator. Transforms a directory of templates (of varying types) into HTML.
https://www.11ty.dev/
MIT License
16.86k stars 487 forks source link

Nested Collections #955

Closed zachleat closed 4 years ago

zachleat commented 4 years ago

I believe some other tools call this taxonomies

This could enable some other neat things like nested levels of pagination. An example of a workaround for two levels of pagination can be found here https://github.com/11ty/eleventy/issues/332

Sold best by this tweet: https://twitter.com/sirinath/status/1230855052547514369

Tags can be hierarchically bundled together by different criteria. E.g. tag 'rust' in category 'programming' can be kept sperate from tag 'rust' in 'metallurgy'. 'Star' in 'music' can be separated from 'star' in 'cosmology' in a 'series' of posts on 'raggae'.

See also

zachleat commented 4 years ago

This repository is now using lodash style issue management for enhancements. This means enhancement issues will now be closed instead of leaving them open.

View the enhancement backlog here. Don’t forget to upvote the top comment with 👍!

sirinath commented 4 years ago

Best writeup on this is:

Also might be interesting:

Other tools which have it:

paulshryock commented 4 years ago

I feel like custom taxonomies are already built into eleventy, even if it's not documented as such.

For example:

---
title: 'Hello World'
contentType: 'article'
category: 'news'
tags: [ 'greeting', 'friendly' ]
---

In .eleventy.js, create an articles collection:

module.exports = function (eleventyConfig) {
  eleventyConfig.addCollection('articles', collection => {
    return collection.getAll().filter(post => post.data.contentType === 'article'))
  })
}

Then in a Javascript data file, query and filter data as needed.

data.articles = collections.articles.filter((article) => {
  return article.category === 'news' && article.tags.includes('greeting')
})

Something like that?

Although I'm not sure if it's possible to access the Eleventy collections object from JavaScript data files.

sielay commented 4 years ago

I don't want here to promote my plugin, but you can find here examples how to create taxonomies and paginate on them. I'm still to make few improvements. First thing I'd like do anyhow is to allow disabling native support for tags, as it makes such approach a bit more problematic.

https://github.com/sielay/eleventy-plugin-blog/blob/master/index.js#L156

All is mutation of idea promoted by @jeromecoupe https://www.webstoemp.com/blog/basic-custom-taxonomies-with-eleventy/

hidegh commented 3 years ago

@zachleat I'd also consider nested collections, which HEXO has out of the box e.g.: /collections/technical/testing/1 or /collections/technical/testing/unit-tests/1

Again here (beside nesting) we can have 2 things to solve:

  1. do we want to display items (and counts) to a category (we might have just a pure nested category listing)
  2. if so, do we want to display immediate items only (or do we want to include items that belong to the subcategories of the currently selected category)

Paging can be also interesting, as we could page over:

  1. the merged sub-category + item list
  2. only over items
m4rrc0 commented 1 year ago

Hey everyone. After doing some digging, I think I can safely say that this feature request's importance is being overlooked. I have found many Github issues pointing to the same kind of request. Of course, some are duplicates but you can look at it any way you want, many people have this problem and different solutions are used while not exactly knowing what the impact is on build performance, maintainability, flexibility of the data structure, ...

In the enhancement backlog alone, nr 7 and 8 (in order of number of votes) point to the same request.

Then there are requests like Programmatically create pages from data files #136 which in fact point to the same issue of lacking control over how pages are built and/or dissociating the relation between 1 file => 1 flat collection.

I totally get that not everyone needs this feature and that there are workarounds. It just seems to me that there are more people needing this than meets the eye.

To try and make my case, and in an effort of compiling what has been discussed on the topic, here are the issues and discussions I could find about this topic (sorry this isn't sorted in any relevant manner):

Non core projects trying to solve this:

I challenge everyone to find more (non-trivial) issues on any other topic! 🤣

I think all those requests have found workarounds to make their use cases work but there is still no canonical way to handle this in Eleventy I believe (with all the obvious short and long-term consequences of hacking around an issue).

Isn't it time to have a proper discussion about this? 😄

(And in the meantime I'll find my own workaround 😅)