www.byjp.me/layouts/partials/claps.html
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

21 lines
No EOL
998 B
HTML

{{- $relperma := .url -}}
{{- $style := .style | default "clap" -}}
{{- $interactionCount := partial "interaction-count.obj" page -}}
<form class="claps" action="https://{{ site.Params.clapsHost }}{{ $relperma }}" method="post">
<button type="submit" title="Show appreciation for the post on this page" data-interactions="{{ $interactionCount }}">
{{- partial "svg.html" (dict "name" $style) -}}
{{- $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 -}}
{{- $clapCount := add $interactionCount ((index $data $relperma) | default 0) -}}
{{- with $clapCount }}<span>{{ . }}</span>{{ end -}}
{{- end -}}
{{- else -}}
{{- errorf "Unable to get all clap counts" -}}
{{- end -}}
</button>
</form>