mirror of
https://github.com/by-jp/www.byjp.me.git
synced 2025-08-10 14:55:41 +01:00
Fix claps
This commit is contained in:
parent
c974158793
commit
f120f0831b
5 changed files with 31 additions and 3 deletions
|
@ -17,7 +17,7 @@ Here in my little career break I'm spending a lot of time thinking about _commun
|
|||
|
||||
Yesterday I built a clap button, the one you can see below this paragraph, and on every page at the bottom of the post (though sometimes its a heart instead of a clap, for aesthetic reasons). If you click it it lets me know you appreciate my post, and keeps track of how many times that's happened (you can press it more than once if you really like something!)
|
||||
|
||||
<figure style="text-align:center">{{< claps >}}<br/><small style="font-style: italic">Press this to show appreciation!</small></figure>
|
||||
{{< claps >}}
|
||||
|
||||
I decided to make this button totally anonymous; this makes it much easier for you to use, but the lack of tracking also means that—for me—it's a feel good vibe rather than data I can get analytical over. If you like the sound of it, you can try it out 😜
|
||||
|
||||
|
|
|
@ -23,4 +23,4 @@ You may also want to visit:
|
|||
=> / 🏡 Home
|
||||
{{ range .Site.Menus.main -}}
|
||||
=> {{ .URL | relURL }} {{ .Name }}
|
||||
{{ end -}}
|
||||
{{ end -}}
|
||||
|
|
3
layouts/shortcodes/claps.gmi
Normal file
3
layouts/shortcodes/claps.gmi
Normal file
|
@ -0,0 +1,3 @@
|
|||
_Sorry, my clap button works via HTTP, and isn't available over Gemini (yet)._
|
||||
|
||||
=> https://www.byjp.me{{ replace .Page.RelPermalink "index.gmi" "" }} View this page on the WWW instead
|
|
@ -1 +1,4 @@
|
|||
{{ partial "claps.html" (dict "url" .Page.RelPermalink) }}
|
||||
<figure style="text-align:center">
|
||||
{{- partial "claps.html" (dict "url" .Page.RelPermalink) }}<br/>
|
||||
<small style="font-style: italic">Press this to show appreciation!</small>
|
||||
</figure>
|
22
layouts/shortcodes/topclaps.gmi
Normal file
22
layouts/shortcodes/topclaps.gmi
Normal file
|
@ -0,0 +1,22 @@
|
|||
{{- $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 -}}
|
||||
{{ $claps = $claps | append (dict "path" $path "count" $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 -}}
|
Loading…
Reference in a new issue