mirror of
https://github.com/by-jp/www.byjp.me.git
synced 2025-08-09 05:36:07 +01:00
This means that people appreciating my posts on other platforms get a single clap per interaction type (eg. comment or star or repost etc.)
43 lines
1.7 KiB
HTML
43 lines
1.7 KiB
HTML
{{- $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 -}}
|
|
<ol class="small-post-list">
|
|
{{- 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)) -}}
|
|
<li>
|
|
{{ partial "svg.html" (dict "name" $typeSVG) }}
|
|
<a href="{{.RelPermalink}}">
|
|
{{- with .Title -}}{{ . }}{{ else }}{{ .Type | singularize | title }}{{ end -}}
|
|
</a>
|
|
<small style="opacity: 0.6">{{ partial "svg.html" (dict "name" "clap") }} {{ $count }}</small>
|
|
</li>
|
|
{{- end -}}
|
|
{{- end }}
|
|
</ol>
|
|
<script>
|
|
const list = document.currentScript.previousSibling;
|
|
for (const clap of list.querySelectorAll('li')) {
|
|
// This clapKey is authoritative in main.js
|
|
const clapKey = `clap:${clap.children[1].pathname}`;
|
|
if (localStorage.getItem(clapKey)) {
|
|
clap.children[2].classList.add('accent')
|
|
}
|
|
}
|
|
</script>
|
|
{{- end -}}
|
|
{{- else -}}
|
|
{{- errorf "Unable to get all clap counts" -}}
|
|
{{- end -}}
|