Zotero Integration Nunjucks - Combine groupby with dictsort?

I’m trying to get some of my templates in Obsidian working together with using Zotero and for this I want to write a corresponding (adapted) template.

I’m almost happy with it but still struggling with one thing: Annotations from Zotero are properly read by the Obsidian plugin which extracts them based on their highlighting color and even grouping works as I would like to. However, I would like to have a certain order in which they’re imported.

The following is a macro I’m using for a different function and it shows the Order I would like to have the groups sorted:

{%- macro colorValueToName(color) -%}
    {%- switch color -%}
        {%- case "#ff6666" -%}
        {%- case "#2ea8e5" -%}
            TODO / follow up
        {%- case "#ffd400" -%}
        {%- case "#a28ae5" -%}
        {%- case "#5fb236" -%}
        {%- default -%}
            Interesting but not relevant
    {%- endswitch -%}
{%- endmacro -%}

Now, when “Good” (green) comes before “Questionable” in the annotations, the order will be accordingly. I understand, that I’ll have to define most likely a dict and use dictsort somehow but I’m unsure how to do so.

The relevant code part where the annotations are fetched and group is this:

## Annotations
{% persist "annotations" %}
{% set annots = annotations | filterby("date", "dateafter", lastImportDate) -%}
{% if annots.length > 0 %}
### Imported on {{importDate | format("YYYY-MM-DD h:mm a")}}

{% for color, annots in annots | groupby("color") -%}
#### {{colorValueToName(color)}}

{% for annot in annots -%}
> [!quote{% if annot.color %}|{{annot.color}}{% endif %}] {{calloutHeader(annot.type)}}

[...removed unrelated code]

{% endfor -%}
{% endfor -%}
{% endif %}
{% endpersist %}

I’m open for thoughts and suggestions. I would think that somewhat has to be done with {% for color, annots in annots | groupby(“color”) -%}