From b185f09fa25daa55ae4e50dbe00ada569377e744 Mon Sep 17 00:00:00 2001 From: "M. Taylor Saotome-Westlake" Date: Sat, 18 Apr 2020 16:41:16 -0700 Subject: [PATCH] comment counter links! --- theme/static/css/main.css | 5 +++++ theme/static/js/comment_counts.js | 30 ++++++++++++++++++++++++++++++ theme/templates/index.html | 5 +++++ 3 files changed, 40 insertions(+) create mode 100644 theme/static/js/comment_counts.js diff --git a/theme/static/css/main.css b/theme/static/css/main.css index 8531a76..057c4d0 100644 --- a/theme/static/css/main.css +++ b/theme/static/css/main.css @@ -368,3 +368,8 @@ p.flower-break { .footnote { font-size: 85%; } + +.comments-link-container { + font-weight: bold; + font-size: 85%; +} diff --git a/theme/static/js/comment_counts.js b/theme/static/js/comment_counts.js new file mode 100644 index 0000000..d0df09b --- /dev/null +++ b/theme/static/js/comment_counts.js @@ -0,0 +1,30 @@ +function placeCommentCounts() { + let containers = Array.from(document.querySelectorAll(".comments-link-container")); + let paths = containers.map(function(span) { return span.dataset.path; }); + + let request = new XMLHttpRequest(); + + request.open('POST', 'http://unremediatedgender.space/isso/count', true); + request.setRequestHeader("Content-Type", "application/json"); + request.send(JSON.stringify(paths)); + + request.onload = function() { + if (this.status >= 200 && this.status < 400) { + let counts = JSON.parse(this.response); + for (let [i, container] of containers.entries()) { + let a = document.createElement('a'); + let count = counts[i]; + let pluralizer = count === 1 ? "" : "s"; + let text = document.createTextNode(`${count} comment${pluralizer}`); + a.appendChild(text); + a.href = `${paths[i]}#isso-thread`; + container.appendChild(a); + } + } + }; + +} + +document.addEventListener("DOMContentLoaded", function() { + placeCommentCounts(); +}); diff --git a/theme/templates/index.html b/theme/templates/index.html index 4095ae9..c28077e 100644 --- a/theme/templates/index.html +++ b/theme/templates/index.html @@ -1,6 +1,10 @@ {% extends "base.html" %} {% block content_title %}{% endblock %} +{% block scripts %} + +{% endblock %} + {% block content %} {% for article in articles_page.object_list %} @@ -9,6 +13,7 @@ {% include 'metadata.inc.html' %} {{ article.content }} +
{% endfor %} -- 2.17.1