{% macro fmt_commit(commit) -%}
* {{ commit.message.splitlines()[0].rstrip() | regex_replace("^[^\(]+\(([^\)]+)\)","**\\1**") }} ([`{{ commit.short_hash }}`]({{ commit.hexsha | commit_hash_url }}))
{%- endmacro %}
# CHANGELOG
{%- if context.history.unreleased | length > 0 -%}
{# UNRELEASED #}
## *Unreleased*
{%  for type_, commits in context.history.unreleased | dictsort %}
### {{ type_ | replace("unknown", "general") | capitalize }}
{%    for commit in commits %}
{{ fmt_commit(commit) }}
{%    endfor %}{%
    endfor %}{%
endif %}
{% for version, release in context.history.released.items() -%}
{%  if release["elements"].keys() | reject("==", "chore") | list() | length() -%}
{# RELEASED #}
## {{ version.as_semver_tag() }} ({{ release.tagged_date.strftime("%Y-%m-%d") }})
{%    for type_, commits in release["elements"] | dictsort %}{%
        if type_ != "chore" %}
### {{ type_ | replace("unknown", "general") | capitalize }}
{%        for commit in commits %}
{{ fmt_commit(commit) }}
{%        endfor %}{%
        endif %}{%
      endfor -%}{%-
    endif -%}{%-
   endfor -%}