{% for entry in tree %}

# {{ entry.version }}{% if entry.date %} ({{ entry.date }}){% endif %}

{% for change_key, changes in entry.changes.items() %}

{% if change_key %}
## {{ change_key }}
{% endif %}
{% set scopemap = {
  'changelog': 'Changelog',
  'contributing': 'Contributing guide',
  'helpers': 'Helpers',
  'sphinx': 'Rendered documentation',
  'typeannotation': 'Type annotation',
} %}

{# track what changelog scope we already saw for this change_key #}
{% set ns = namespace(saw_scopes=[]) %}
{% for change in changes | sort(attribute=scope) %}
{% set indent = '' %}
{% if change.scope %}
{% set indent = '  ' %}
{# write out scope, if it is new #}
{% if change.scope not in ns.saw_scopes %}
{% set ns.saw_scopes = ns.saw_scopes + [change.scope] %}
- {{ scopemap.get(change.scope, change.scope) }}:
{% endif %}
{% endif %}
{%- if change.message %}
{{ indent }}- {{ change.message }}
{%- endif %}
 [[{{ change.sha1 | truncate(8, true, '') }}]](https://github.com/datalad/datalad-next/commit/{{ change.sha1 | truncate(8, true, '') }})
{% endfor %}
{% endfor %}
{% endfor %}
