Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested Collections #955

Closed
zachleat opened this issue Feb 21, 2020 · 6 comments
Closed

Nested Collections #955

zachleat opened this issue Feb 21, 2020 · 6 comments
Labels
enhancement needs-votes A feature request on the backlog that needs upvotes or downvotes. Remove this label when resolved.

Comments

@zachleat
Copy link
Member

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 #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 zachleat added enhancement needs-votes A feature request on the backlog that needs upvotes or downvotes. Remove this label when resolved. labels Feb 21, 2020
@zachleat
Copy link
Member Author

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
Copy link

sirinath commented Feb 21, 2020

Best writeup on this is:

Also might be interesting:

Other tools which have it:

@paulshryock
Copy link
Contributor

paulshryock commented Mar 10, 2020

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
Copy link

sielay commented Jun 15, 2020

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
Copy link

hidegh commented Feb 16, 2021

@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
Copy link

m4rrc0 commented Mar 27, 2023

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 😅)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement needs-votes A feature request on the backlog that needs upvotes or downvotes. Remove this label when resolved.
Projects
None yet
Development

No branches or pull requests

6 participants