{{- $type := .Get "type" -}} <!-- e.g. "media" -->
{{- $data := .Site.Data.links -}}
{{- if $type -}}
  {{- $data = where $data "type" $type -}}
{{ end }}
{{- range sort $data "date" "desc" }}
  <ul>
    <li>{{.desc}} – 
    {{- $len := (len .links) -}} <!-- amount of elements under .links -->
      {{- range $index, $element := .links -}} <!-- range over links, but keep index -->
        {{ with .href }}<a href="{{.}}">{{ end }}{{.text}}{{ with .href }}</a>{{end}}
        {{- if ne (add $index 1) $len -}}, {{- end -}} <!-- only append comma if not last element (index starts with 0) -->
      {{- end -}}
      {{- with .date }} ({{.}}){{ end }} 
      {{ range .tags }}<span class="label label-success">{{ . }}</span>&nbsp;{{ end }}
    </li>
  </ul>
{{ end }}
