about summary refs log tree commit diff
path: root/concat.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-04-26 15:57:07 -0400
committerJune McEnroe <june@causal.agency>2020-04-26 16:04:43 -0400
commit7953ea0aef6d6d7110c95f368c07c1ac8b6223b8 (patch)
treeb10d55b0e940dd8a287cb5b51b732c0faef25ae5 /concat.c
parentGenerate XHTML content in Atom entries (diff)
downloadbubger-7953ea0aef6d6d7110c95f368c07c1ac8b6223b8.tar.gz
bubger-7953ea0aef6d6d7110c95f368c07c1ac8b6223b8.zip
Generate index.atom
Diffstat (limited to 'concat.c')
-rw-r--r--concat.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/concat.c b/concat.c
index 8e165d2..7be35e0 100644
--- a/concat.c
+++ b/concat.c
@@ -169,7 +169,7 @@ static void concatThread(struct List thread, const struct Envelope *envelope) {
 		FILE *file = fopen(path, "w");
 		if (!file) err(EX_CANTCREAT, "%s", path);
 
-		error = atomFeedOpen(file, envelope);
+		error = atomThreadOpen(file, envelope);
 		if (error) err(EX_IOERR, "%s", path);
 
 		for (size_t i = 0; i < flat.len; ++i) {
@@ -178,7 +178,7 @@ static void concatThread(struct List thread, const struct Envelope *envelope) {
 			if (error) err(EX_IOERR, "%s", path);
 		}
 
-		error = atomFeedClose(file) || fclose(file);
+		error = atomThreadClose(file) || fclose(file);
 		if (error) err(EX_IOERR, "%s", path);
 	}
 
@@ -230,6 +230,25 @@ static int compar(const void *_a, const void *_b) {
 }
 
 void concatIndex(struct List threads, const struct Envelope *envelopes) {
+	const char *path = "index.atom";
+	FILE *file = fopen(path, "w");
+	if (!file) err(EX_CANTCREAT, "%s", path);
+
+	int error = atomIndexOpen(file);
+	if (error) err(EX_IOERR, "%s", path);
+
+	struct List flat = {0};
+	listFlatten(&flat, threads);
+	for (size_t i = flat.len - 1; i < flat.len; --i) {
+		uint32_t uid = dataCheck(flat.ptr[i], Number).number;
+		error = concatFile(file, uidPath(uid, "atom"));
+		if (error) err(EX_IOERR, "%s", path);
+	}
+	listFree(flat);
+
+	error = atomIndexClose(file) || fclose(file);
+	if (error) err(EX_IOERR, "%s", path);
+
 	struct Sort *order = calloc(threads.len, sizeof(*order));
 	if (!order) err(EX_OSERR, "calloc");
 
@@ -245,11 +264,11 @@ void concatIndex(struct List threads, const struct Envelope *envelopes) {
 	}
 	qsort(order, threads.len, sizeof(*order), compar);
 
-	const char *path = "index.html";
-	FILE *file = fopen(path, "w");
+	path = "index.html";
+	file = fopen(path, "w");
 	if (!file) err(EX_CANTCREAT, "%s", path);
 
-	int error = htmlIndexHead(file);
+	error = htmlIndexHead(file);
 	if (error) err(EX_IOERR, "%s", path);
 
 	if (concatHead) {