{#- macro: render_commit -#}
{%- macro render_commit(commit) -%}
- {% if commit.convention.scope %}**{{ commit.convention.scope }}:** {% endif %}{{ commit.convention.subject }} ([{{ commit.hash|truncate(7, True, '') }}]({{ commit.url }}))
{%- if commit.text_refs.issues_not_in_subject %}, related to {% for issue in commit.text_refs.issues_not_in_subject -%}
[{{ issue.ref }}]({{ issue.url }}){% if not loop.last %}, {% endif -%}
{%- endfor -%}
{%- endif -%}
{%- endmacro -%}

{#- macro: render_section -#}
{%- macro render_section(section) -%}
### {{ section.type or "Misc" }}

{% for commit in section.commits|sort(attribute='author_date',reverse=true)|unique(attribute='subject') -%}
{{ render_commit(commit) }}
{% endfor %}
{%- endmacro -%}

{#- macro: render_version -#}
{%- macro render_version(version) -%}
{%- if version.tag or version.planned_tag -%}
<a name="{{ version.tag or version.planned_tag }}"></a>

## [{{ version.tag or version.planned_tag }}]({{ version.compare_url }})
{%- else -%}
<a name="Unreleased"></a>
## Unreleased ([compare]({{ version.compare_url }}))
{%- endif -%}
{% if version.date %} ({{ version.date }}){% endif %}
{% for type in changelog.sections %}
{%- if type in version.sections_dict %}
{%- with section = version.sections_dict[type] %}
{{ render_section(section) }}
{%- endwith %}
{%- endif %}
{%- endfor %}
{%- if not (version.tag or version.planned_tag) %}
<!-- insertion marker -->{% endif %}
{% endmacro -%}

{#- template -#}
<!-- insertion marker -->
{% for version in changelog.versions_list -%}
{{ render_version(version) }}
{%- endfor -%}
