From f120f0831bd5fff41058fc3c1b7b45db9d024b5f Mon Sep 17 00:00:00 2001 From: JP Hastings-Spital Date: Mon, 29 Apr 2024 17:56:30 +0100 Subject: [PATCH] Fix claps --- content/posts/easy-appreciation/index.md | 2 +- layouts/_default/list.gmi | 2 +- layouts/shortcodes/claps.gmi | 3 +++ layouts/shortcodes/claps.html | 5 ++++- layouts/shortcodes/topclaps.gmi | 22 ++++++++++++++++++++++ 5 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 layouts/shortcodes/claps.gmi create mode 100644 layouts/shortcodes/topclaps.gmi diff --git a/content/posts/easy-appreciation/index.md b/content/posts/easy-appreciation/index.md index a61df114..5ba8d497 100644 --- a/content/posts/easy-appreciation/index.md +++ b/content/posts/easy-appreciation/index.md @@ -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!) -
{{< claps >}}
Press this to show appreciation!
+{{< 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 😜 diff --git a/layouts/_default/list.gmi b/layouts/_default/list.gmi index 485a5461..f9bf271e 100644 --- a/layouts/_default/list.gmi +++ b/layouts/_default/list.gmi @@ -23,4 +23,4 @@ You may also want to visit: => / 🏡 Home {{ range .Site.Menus.main -}} => {{ .URL | relURL }} {{ .Name }} -{{ end -}} \ No newline at end of file +{{ end -}} diff --git a/layouts/shortcodes/claps.gmi b/layouts/shortcodes/claps.gmi new file mode 100644 index 00000000..4e79ea08 --- /dev/null +++ b/layouts/shortcodes/claps.gmi @@ -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 \ No newline at end of file diff --git a/layouts/shortcodes/claps.html b/layouts/shortcodes/claps.html index 01e9f520..0b8e89a6 100644 --- a/layouts/shortcodes/claps.html +++ b/layouts/shortcodes/claps.html @@ -1 +1,4 @@ -{{ partial "claps.html" (dict "url" .Page.RelPermalink) }} \ No newline at end of file +
+{{- partial "claps.html" (dict "url" .Page.RelPermalink) }}
+Press this to show appreciation! +
\ No newline at end of file diff --git a/layouts/shortcodes/topclaps.gmi b/layouts/shortcodes/topclaps.gmi new file mode 100644 index 00000000..694b4765 --- /dev/null +++ b/layouts/shortcodes/topclaps.gmi @@ -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 -}}