mirror of
https://github.com/by-jp/www.byjp.me.git
synced 2025-08-08 21:25:56 +01:00
24 lines
No EOL
1.1 KiB
HTML
24 lines
No EOL
1.1 KiB
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 }}">
|
|
{{- partialCached "svg.html" (dict "name" $style) $style -}}
|
|
{{- $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 "%s" . -}}
|
|
{{ else with .Value }}
|
|
{{- $data := .Content | transform.Unmarshal -}}
|
|
{{- $clapCount := (index $data $relperma) | default 0 -}}
|
|
{{- $totalCount := add (int $interactionCount) (int $clapCount) -}}
|
|
{{- with $totalCount }}<span>{{ . }}</span>{{ end -}}
|
|
{{ else }}
|
|
{{ errorf "Unable to get remote resource %q" $url }}
|
|
{{- end -}}
|
|
{{- else -}}
|
|
{{- errorf "Unable to get all clap counts" -}}
|
|
{{- end -}}
|
|
</button>
|
|
</form> |