about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--archive.h2
-rw-r--r--concat.c2
-rw-r--r--html.c30
3 files changed, 28 insertions, 6 deletions
diff --git a/archive.h b/archive.h
index 94db1a6..49f2a1f 100644
--- a/archive.h
+++ b/archive.h
@@ -209,6 +209,6 @@ int htmlMessageOpen(FILE *file, const struct Envelope *envelope);
 int htmlMessageClose(FILE *file);
 int htmlThreadHead(FILE *file, const struct Envelope *envelope);
 int htmlThreadOpen(FILE *file, const struct Envelope *envelope);
-int htmlSubthreadOpen(FILE *file);
+int htmlSubthreadOpen(FILE *file, struct List thread);
 int htmlSubthreadClose(FILE *file);
 int htmlThreadClose(FILE *file);
diff --git a/concat.c b/concat.c
index 04d2e27..94f9bed 100644
--- a/concat.c
+++ b/concat.c
@@ -81,7 +81,7 @@ static int concatHTML(FILE *file, struct List thread) {
 	for (size_t i = 0; i < thread.len; ++i) {
 		if (thread.ptr[i].type == List) {
 			error = 0
-				|| htmlSubthreadOpen(file)
+				|| htmlSubthreadOpen(file, thread.ptr[i].list)
 				|| concatHTML(file, thread.ptr[i].list)
 				|| htmlSubthreadClose(file);
 		} else {
diff --git a/html.c b/html.c
index 090bfab..352e229 100644
--- a/html.c
+++ b/html.c
@@ -205,14 +205,36 @@ int htmlThreadOpen(FILE *file, const struct Envelope *envelope) {
 	return error;
 }
 
-int htmlSubthreadOpen(FILE *file) {
-	return templateRender(
-		file, TEMPLATE(<section class="subthread">), NULL, NULL
+static size_t threadCount(struct List thread) {
+	size_t count = 0;
+	for (size_t i = 0; i < thread.len; ++i) {
+		if (thread.ptr[i].type == List) {
+			count += threadCount(thread.ptr[i].list);
+		} else {
+			count++;
+		}
+	}
+	return count;
+}
+
+int htmlSubthreadOpen(FILE *file, struct List thread) {
+	const char *template = TEMPLATE(
+		<details class="subthread" open>
+			<summary>[replies] repl[ies]</summary>
 	);
+	size_t count = threadCount(thread);
+	char replies[32];
+	snprintf(replies, sizeof(replies), "%zu", count);
+	struct Variable vars[] = {
+		{ "replies", replies },
+		{ "ies", (count > 1 ? "ies" : "y") },
+		{0},
+	};
+	return templateRender(file, template, vars, escapeXML);
 }
 
 int htmlSubthreadClose(FILE *file) {
-	return templateRender(file, TEMPLATE(</section>), NULL, NULL);
+	return templateRender(file, TEMPLATE(</details>), NULL, NULL);
 }
 
 int htmlThreadClose(FILE *file) {