summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-04-15 20:25:26 -0400
committerJune McEnroe <june@causal.agency>2020-04-15 20:25:26 -0400
commit2c222f14103a1c3b6e29ad5fcd84e92594665dbe (patch)
treea7d4f6f829b954210a28740f8bb95f3ee6ff6c80
parentRewrite HTML rendering (diff)
downloadbubger-2c222f14103a1c3b6e29ad5fcd84e92594665dbe.tar.gz
bubger-2c222f14103a1c3b6e29ad5fcd84e92594665dbe.zip
Wrap subthreads in <details> with reply count
-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) {
s that links to commits always limit by the path known to that commit. If we didn't do this we would need to walk down the log diff'ing every commit whenever we want to show a commit. The drawback is that the "Log" link in the top bar of such a page links to the log limited by the old name, so it will only show pre-rename commits. I consider this a reasonable trade-off since the "Back" button still works and the log matches the path displayed in the top bar. Since following renames requires running diff on every commit we consider, I've added a knob to the configuration file to globally enable/disable this feature. Note that we may consider a large number of commits the revision walking machinery no longer performs any path limitation so we have to examine every commit until we find a page full of commits that affect the target path or something related to it. Suggested-by: René Neumann <necoro@necoro.eu> Signed-off-by: John Keeping <john@keeping.me.uk> 2015-08-12shared: make cgit_diff_tree_cb publicJohn Keeping This will allow us to use this nice wrapper function elsewhere, avoiding dealing with the diff queue when we only need to inspect a filepair. Signed-off-by: John Keeping <john@keeping.me.uk> 2015-08-12t0110: Chain together using &&Jason A. Donenfeld 2015-08-12about: always ensure page has a trailing slashJason A. Donenfeld Otherwise we can't easily embed links to other /about/ pages. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> 2015-08-12filters: apply HTML escapingLazaros Koromilas http://www.w3.org/International/questions/qa-escapes#use 2015-08-12git: update to v2.5.0Christian Hesse Update to git version v2.5.0. * Upstream commit 5455ee0573a22bb793a7083d593ae1ace909cd4c (Merge branch 'bc/object-id') changed API: for_each_ref() callback functions were taught to name the objects not with "unsigned char sha1[20]" but with "struct object_id". * Upstream commit dcf692625ac569fefbe52269061230f4fde10e47 (path.c: make get_pathname() call sites return const char *) Signed-off-by: Christian Hesse <mail@eworm.de> 2015-08-12Fix processing of repo.hide and repo.ignoreDaniel Reichelt