comment counter links!
authorM. Taylor Saotome-Westlake <ultimatelyuntruethought@gmail.com>
Sat, 18 Apr 2020 23:41:16 +0000 (16:41 -0700)
committerM. Taylor Saotome-Westlake <ultimatelyuntruethought@gmail.com>
Sat, 18 Apr 2020 23:41:16 +0000 (16:41 -0700)
theme/static/css/main.css
theme/static/js/comment_counts.js [new file with mode: 0644]
theme/templates/index.html

index 8531a76..057c4d0 100644 (file)
@@ -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 (file)
index 0000000..d0df09b
--- /dev/null
@@ -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();
+});
index 4095ae9..c28077e 100644 (file)
@@ -1,6 +1,10 @@
 {% extends "base.html" %}
 {% block content_title %}{% endblock %}
 
+{% block scripts %}
+  <script src="/theme/js/comment_counts.js"></script>
+{% endblock %}
+
 {% block content %}
 
 {% for article in articles_page.object_list %}
@@ -9,6 +13,7 @@
     {% include 'metadata.inc.html' %}
     {{ article.content }}
   </article>
+  <span class="comments-link-container" data-path="/{{ article.url }}" id="{{ article.slug }}-comments-link-container"></span>
   <hr />
 {% endfor %}