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

group_by filter #10

Open
jesseditson opened this issue Feb 21, 2024 · 0 comments
Open

group_by filter #10

jesseditson opened this issue Feb 21, 2024 · 0 comments

Comments

@jesseditson
Copy link
Owner

Would make certain site types a little easier. For instance, tags on a blog post.

Current solution:

{% assign groups_str = '' %}
{% for t in post.tags %}
  {% assign group = t.name | prepend: ',' %}
  {% unless groups_str contains group %}
    {% assign groups_str = groups_str | append: group %}
  {% endunless %}
{% endfor %}
{% assign groups = groups_str | remove_first: ',' | split: ',' %}

{% for group in groups %}
  {{group}}
{% endfor %}

The implied data model is:

[post]
[post.tags]
name = "string"

Which (somewhat annoyingly) expands to

// my-post.toml

[[tags]]
name = "foo"

[[tags]]
name = "bar"

A string array type would further simplify definition but is not currently planned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant