From 0e7bd2d0cac33a0c38fdf46802ee617dcc67a3d5 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Tue, 28 Mar 2023 12:53:02 -0400 Subject: [PATCH] Add voting system --- themes/red/assets/js/voting.js | 18 ++++++++++++++++++ themes/red/layouts/_default/art-detail.html | 3 ++- themes/red/layouts/partials/voting.html | 16 ++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 themes/red/assets/js/voting.js create mode 100644 themes/red/layouts/partials/voting.html diff --git a/themes/red/assets/js/voting.js b/themes/red/assets/js/voting.js new file mode 100644 index 0000000..7950266 --- /dev/null +++ b/themes/red/assets/js/voting.js @@ -0,0 +1,18 @@ +function refresh(slug) { + fetch('https://voting.redstrate.com/votes/view/' + slug) + .then(function(response) { + return response.json(); + }) + .then(function(data) { + console.log(data) + document.getElementById("num-votes").innerHTML = data["votes"] + " votes"; + }); +} + +function addVote(slug) { + const request = new Request("https://voting.redstrate.com/votes/submit/" + slug, { + method: "POST" + }); + fetch(request) + .then((response) => { refresh(slug) }); +} diff --git a/themes/red/layouts/_default/art-detail.html b/themes/red/layouts/_default/art-detail.html index da4984b..8145ea3 100644 --- a/themes/red/layouts/_default/art-detail.html +++ b/themes/red/layouts/_default/art-detail.html @@ -4,7 +4,7 @@
{{ with resources.Get .Params.filename }} - {{ $.Params.alt_text }} + {{ $.Params.alt_text }} {{ end }} @@ -78,6 +78,7 @@ {{ end }} + {{ partial "voting" . }}
diff --git a/themes/red/layouts/partials/voting.html b/themes/red/layouts/partials/voting.html new file mode 100644 index 0000000..cee66f3 --- /dev/null +++ b/themes/red/layouts/partials/voting.html @@ -0,0 +1,16 @@ +
+ + +

...

+
+ +{{ $site := resources.Get "js/voting.js" }} +{{ if hugo.IsProduction }} + {{ $site = $site | minify | fingerprint | resources.PostProcess }} +{{ end }} + + + +