8000 Sort foundation members alphabetically in display by sanjayy-gowdaa · Pull Request #2763 · matrix-org/matrix.org · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Sort foundation members alphabetically in display #2763

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

Merged
merged 2 commits into from
May 25, 2025

Conversation

sanjayy-gowdaa
Copy link
Contributor

Solves Issue (#2756 )
This PR updates the Tera template to sort Foundation members alphabetically by name within each tier (Platinum, Gold, Silver, etc.) during rendering. The supporters.toml file remains unchanged.

Thank you for the clarification! I've implemented the sorting directly in the Tera template as suggested. Let me know if any changes are needed.

Copy link
Collaborator
@HarHarLinks HarHarLinks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, this is good so far. If you check the current manual ordering, notice that we order the entries irrespective of capitalization. Could you add that as well?

@HarHarLinks HarHarLinks added bug Something is broken. aesthetic Visual inconsistencies or improvements meta Things that are foundation related or external services mentioning matrix that need changes labels May 24, 2025
@sanjayy-gowdaa
Copy link
Contributor Author
sanjayy-gowdaa commented May 24, 2025

Thank you for the suggestion!

I attempted to implement case-insensitive sorting in the Tera template to match the current manual ordering (ignoring capitalization). Here are the approaches I tried:

Attempt 1:
{% for supporter in supporters.silver | sort(attribute="name" | lower) %}

Just applies lower to the string "name", not the actual values.
So it gets ignored and ends up doing a normal case-sensitive sort.

Attempt 2: Inline dictionary creation with concat

{# Prepare a list for sorting Silver supporters #}
                {% set silver_to_sort = [] %}
                {% if supporters.silver %}
                    {% for supporter_item in supporters.silver %}
                        {% set silver_to_sort = silver_to_sort | concat(with=[{"sort_name": supporter_item.name | lower, "data": supporter_item }]) %}
                    {% endfor %}
                {% endif %}
                {% set sorted_silver = silver_to_sort | sort(attribute="sort_name") %}

                {% for item in sorted_silver %}
                    {% set supporter = item.data %} {# Get original supporter data #}
                    <a href="{{ supporter.website }}" target="_blank" class="supporters-card">
                        <img src="/support/{{ supporter.logo }}" alt="{{ supporter.name }}'s logo">
                        <span>{{ supporter.name }}</span>
                    </a>
                {% endfor %}

Error: expected a value that can be negated

Attempt 3: Create a dictionary using set

{% set sort_item = {
    "sort_name": supporter_item.name | lower,
    "data": supporter_item
} %}

Error:expected a value that can be negated or an array of values

Tera doesn’t support setting dictionaries directly inside templates.

What would be the best way to proceed?

@HarHarLinks
Copy link
Collaborator

Sorry, this turned out to be trickier than expected. Ideally, Tera would simply support a flag for sorting case-insensitively. This is not the case but looks to be on the horizon: Keats/tera#967. We should migrate to it as soon as it becomes available, but that is not today.

Your ideas are good, Tera is just pretty limiting, and even more so since we can't just extend its filters as we need it compiled into Zola.

Sadly, {% for supporter in supporters.silver | sort(attribute="name" | lower) %} is not valid syntax. The right order would be {% for supporter in supporters.silver | lower | sort(attribute="name") %}, except lower is applied to individual strings and not arrays (and we lose the correct capitalisation). So this won't work.

The second attempt is also good, but as you figured out in attempt 3 Tera doesn't support creating "dictionaries" ad-hoc. We have to dig deep in our box of tricks.

To be sure if this is possible at all, I had to implement it and find a working solution. Here is what I came up with plus some explanations. Some variable names are not yet ideal:

    {# we create an array of only the supporter names in lower case so we may sort it later #}
    {% set lower_supporters = [] %}
    {% for lower_supporter in supporters.silver | map(attribute="name") %}
        {% set_global lower_supporters = lower_supporters | concat(with=[lower_supporter | lower ]) %}
    {% endfor %}

    {% for lower_supporter in lower_supporters | sort %}
        {# we search the original supporter object that matches our lower-cased name #}
        {# this is not ideal since we blow up the complexity up to O(n^2) but I don't see another way #}
        {% for supporter in supporters %}
            {# note the order of operators #}
            {% if supporter.name | lower == lower_supporter %}
                {% set_global current_supporter = supporter %}
                {% break %}
            {% endif %}
        {% endfor %}
        {# we can now use the supporter object #}
    <a href="{{ current_supporter.website }}" target="_blank" class="supporters-card">
        <img src="/support/{{ current_supporter.logo }}" alt="{{ current_supporter.name }}'s logo">
        <span>{{ current_supporter.name }}</span>
    </a>
    {% endfor %}

If you would like to continue, can you clean that up a bit and create a macro for that next to our other macros in /templates/macros/ so we don't have to maintain copies of this code? nominee.html should be a good example of how to do it.

@sanjayy-gowdaa
Copy link
Contributor Author

Resolves(#2756 )

Thanks for the detailed breakdown! This turned out to be a great learning opportunity I gained a much better understanding of Tera’s limitations and some creative ways to work around them, especially regarding sorting and macro structuring.

I’ve taken your suggestion and implemented the workaround as a macro in /templates/macros/supporters.html, inspired by the structure in nominee.html. I also refactored the main support.html file to use the macro.

Copy link
Collaborator
@HarHarLinks HarHarLinks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, thanks again!

@HarHarLinks HarHarLinks merged commit 75fb2d4 into matrix-org:main May 25, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aesthetic Visual inconsistencies or improvements bug Something is broken. meta Things that are foundation related or external services mentioning matrix that need changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0