{{ $allVersions := . }}
{{- range $index, $changes := . }}{{ with $changes -}}
{{ if gt (len $allVersions) 1 -}}
# Changelog for [{{ .Version }}] ({{ .Date }})

The following sections list the changes for {{ .Version }}.

{{/* creating version compare links */ -}}
{{ $next := add1 $index -}}
{{ if ne (len $allVersions) $next -}}
{{ $previousVersion := (index $allVersions $next).Version -}}
{{ if eq .Version "unreleased" -}}
[{{ .Version }}]: https://github.com/owncloud/ocis/compare/v{{ $previousVersion }}...master

{{ else -}}
[{{ .Version }}]: https://github.com/owncloud/ocis/compare/v{{ $previousVersion }}...v{{ .Version }}

{{ end -}}
{{ end -}}

{{- /* last version managed by calens, end of the loop */ -}}
{{ if eq .Version "0.1.0" -}}
[{{ .Version }}]: https://github.com/owncloud/ocis/compare/94f19e653e30cdf16dcf23dbaf36c6d753d37ae9...v{{ .Version }}

{{ end -}}
{{ else -}}
# Changes in {{ .Version }}

{{ end -}}

## Summary
{{ range $entry := .Entries }}{{ with $entry }}
* {{ .Type }} - {{ .Title }}: [#{{ .PrimaryID }}]({{ .PrimaryURL }})
{{- end }}{{ end }}

## Details
{{ range $entry := .Entries }}{{ with $entry }}
* {{ .Type }} - {{ .Title }}: [#{{ .PrimaryID }}]({{ .PrimaryURL }})
{{ range $par := .Paragraphs -}}
{{/* Workaround for keeping lists inside of changelog items well formatted */ -}}
{{ if hasPrefix "*" $par }}
  {{ $par | replace " *" "\n  *" }}
{{- else }}
   {{ wrapIndent $par 80 3 -}}
{{ end }}
{{ end -}}
{{ range $url := .IssueURLs }}
   {{ $url -}}
{{ end -}}
{{ range $url := .PRURLs }}
   {{ $url -}}
{{ end -}}
{{ range $url := .OtherURLs }}
   {{ $url -}}
{{ end }}
{{ end }}{{ end -}}
{{ end }}{{ end -}}
