about summary refs log tree commit diff
path: root/concat.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-04-15 19:06:42 -0400
committerJune McEnroe <june@causal.agency>2020-04-15 19:06:42 -0400
commitd72dcfd4665f937eec2d325c10d35a644e9c06ad (patch)
tree81617185483e24ab19a0beefa4c69405a69e596e /concat.c
parentTweak fetchParts naming (diff)
downloadbubger-d72dcfd4665f937eec2d325c10d35a644e9c06ad.tar.gz
bubger-d72dcfd4665f937eec2d325c10d35a644e9c06ad.zip
Rewrite HTML rendering
Diffstat (limited to '')
-rw-r--r--concat.c37
1 files changed, 29 insertions, 8 deletions
diff --git a/concat.c b/concat.c
index a0f451e..04d2e27 100644
--- a/concat.c
+++ b/concat.c
@@ -80,22 +80,21 @@ static int concatHTML(FILE *file, struct List thread) {
 	int error;
 	for (size_t i = 0; i < thread.len; ++i) {
 		if (thread.ptr[i].type == List) {
-			error = concatHTML(file, thread.ptr[i].list);
+			error = 0
+				|| htmlSubthreadOpen(file)
+				|| concatHTML(file, thread.ptr[i].list)
+				|| htmlSubthreadClose(file);
 		} else {
 			uint32_t uid = dataCheck(thread.ptr[i], Number).number;
-			error = htmlThreadOpen(file)
-				|| concatFile(file, pathUID(uid, "html"));
+			error = concatFile(file, pathUID(uid, "html"));
 		}
 		if (error) return error;
 	}
-	for (size_t i = 0; i < thread.len; ++i) {
-		if (thread.ptr[i].type == List) continue;
-		error = htmlThreadClose(file);
-		if (error) return error;
-	}
 	return 0;
 }
 
+const char *concatHead;
+
 void concatData(struct List threads, struct List items) {
 	uint32_t uid = 0;
 	struct Envelope envelope = {0};
@@ -157,5 +156,27 @@ void concatData(struct List threads, struct List items) {
 		if (error) err(EX_IOERR, "%s", path);
 	}
 
+	path = pathThread(envelope.messageID, "html");
+	error = stat(path, &status);
+	if (error || status.st_mtime < uidNewest(flat, "html")) {
+		FILE *file = fopen(path, "w");
+		if (!file) err(EX_CANTCREAT, "%s", path);
+
+		error = htmlThreadHead(file, &envelope);
+		if (error) err(EX_IOERR, "%s", path);
+
+		if (concatHead) {
+			error = concatFile(file, concatHead);
+			if (error) err(EX_IOERR, "%s", path);
+		}
+
+		error = 0
+			|| htmlThreadOpen(file, &envelope)
+			|| concatHTML(file, thread)
+			|| htmlThreadClose(file)
+			|| fclose(file);
+		if (error) err(EX_IOERR, "%s", path);
+	}
+
 	listFree(flat);
 }