--- /dev/null
+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();
+});
{% 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 %}
{% 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 %}