{{- $count := .Get 0 | default 5 -}} {{- $url := printf "https://%s" site.Params.clapsHost -}} {{- $cacheKey := print $url (now.Format "-2006-01-02-15") -}} {{- with try (resources.GetRemote $url (dict "key" $cacheKey)) -}} {{- with .Err -}} {{- errorf "Unable to get top claps: %v" . -}} {{- else with .Value -}} {{- $data := .Content | transform.Unmarshal -}} {{- $claps := slice -}} {{- range $path, $count := $data -}} {{- $interactionCount := partial "interaction-count.obj" (site.GetPage $path) -}} {{ $claps = $claps | append (dict "path" $path "count" (add $interactionCount $count)) }} {{- end -}}
    {{- range (sort $claps "count" "desc" | first $count) -}} {{- $count := .count -}} {{- with site.GetPage .path -}} {{- $postType := partial "post-type.txt" . -}} {{- $typeSVG := index site.Params.defaultSVG (partial "kebab.txt" ($postType | singularize)) -}}
  1. {{ partialCached "svg.html" (dict "name" $typeSVG) $typeSVG }} {{- with .Title -}}{{ . }}{{ else }}{{ .Type | singularize | title }}{{ end -}} {{ partialCached "svg.html" (dict "name" "clap") "clap" }} {{ $count }}
  2. {{- end -}} {{- end }}
{{- else -}} {{- errorf "Unable to get top claps" -}} {{- end -}} {{- else -}} {{- errorf "Unable to get all clap counts" -}} {{- end -}}