www.byjp.me/layouts/shortcodes/topclaps.gmi
JP Hastings-Spital aa3c92b9db Adding interactions to clap count
This means that people appreciating my posts on other platforms get a single clap per interaction type (eg. comment or star or repost etc.)
2024-06-20 14:25:09 +01:00

23 lines
1,005 B
Text

{{- $count := .Get 0 | default 5 -}}
{{- $url := printf "https://%s" site.Params.clapsHost -}}
{{- $cacheKey := print $url (now.Format "-2006-01-02-15") -}}
{{- with resources.GetRemote $url (dict "key" $cacheKey) -}}
{{- with .Err -}}
{{- errorf "%s" . -}}
{{- else -}}
{{- $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 }}
=> {{.RelPermalink}} {{ with .Params.emoji }}{{ . }} {{ end}}{{ with .Title -}}{{ . }}{{ else }}{{ .Type | singularize | title }}{{ end }} ({{ $count }})
{{- end -}}
{{- end }}
{{- end -}}
{{- else -}}
{{- errorf "Unable to get all clap counts" -}}
{{- end -}}