From d72dcfd4665f937eec2d325c10d35a644e9c06ad Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Wed, 15 Apr 2020 19:06:42 -0400 Subject: Rewrite HTML rendering --- concat.c | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) (limited to 'concat.c') 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); } -- cgit 1.4.1