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

Add filter and grouping support #1735

Closed
1 of 2 tasks
haacked opened this issue Nov 19, 2013 · 9 comments · Fixed by #1875
Closed
1 of 2 tasks

Add filter and grouping support #1735

haacked opened this issue Nov 19, 2013 · 9 comments · Fixed by #1875

Comments

@haacked
Copy link

haacked commented Nov 19, 2013

I had a case where I wanted to group a bunch of pages by a property. Here's a naive example of the type of code I would want to write:

{% for group in site.pages.filter(:enabled).group_by(:someProperty) %}
   <h2>{{ group.Name }}</h2>
   <ul>
   {% for item in group.Items %}
      <li>{{ item.FooBar }}</li>
    {% endfor %}
  </ul>
{% endfor %}

This could be a better way to handle grouping blog posts by dates too.

  • group_by
  • where
@benbalter
Copy link
Contributor

Since jsonify dropped, the ability to filter would be absolutely killer. e.g., {{ site.pages | filter:"layout","license" | jsonify }} Perhaps a where filter would be a more Jekyll-y way?

@parkr
Copy link
Member

parkr commented Nov 19, 2013

This is a great idea! Would you filter only by category, or by anything in page.data?

@benbalter
Copy link
Contributor

In my head, I was thinking it was similar to ruby's select behavior, or underscore's where. Iterate through an array of objects and return those objects where the given key matches the specified value.

@parkr
Copy link
Member

parkr commented Nov 19, 2013

@benbalter Hm, I think @haacked's idea of "group_by" would make more sense in this case, as it'd group by a key. Otherwise, we'd have to know both the key and the value. Syntax is doable, but would have to be like filter: "layout => license" and parsed as filter the given array such that only objects whose layout key is "license". I'd probably add two filters here:

  • group_by
  • filter (filter only by ==, or also by include??)

@haacked
Copy link
Author

haacked commented Nov 19, 2013

Would you filter only by category, or by anything in page.data?

Ideally anything in page.data. That'd make it much more powerful.

Also, I don't think select and where capture the group_by semantics. group_by is effectively an aggregation function. Not sure what that corresponds to in Ruby. Sorry. :)

@parkr
Copy link
Member

parkr commented Dec 10, 2013

@haacked #1788 has been merged.

@haacked
Copy link
Author

haacked commented Dec 10, 2013

Yay!

bravo

@haacked
Copy link
Author

haacked commented Dec 10, 2013

Someone on the twitters asked about sorting. I added it here, but should I create a new issue? Thoughts?

@parkr
Copy link
Member

parkr commented Dec 10, 2013

Please create a new issue :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
4 participants