From 7953ea0aef6d6d7110c95f368c07c1ac8b6223b8 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Sun, 26 Apr 2020 15:57:07 -0400 Subject: Generate index.atom --- atom.c | 58 +++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 17 deletions(-) (limited to 'atom.c') diff --git a/atom.c b/atom.c index b0ee921..85393c9 100644 --- a/atom.c +++ b/atom.c @@ -22,8 +22,6 @@ #include "archive.h" -const char *atomBaseURL; - static char *atomID(const struct Envelope *envelope) { struct Variable vars[] = { { "messageID", envelope->messageID }, @@ -33,7 +31,6 @@ static char *atomID(const struct Envelope *envelope) { } static int atomAuthor(FILE *file, struct Address addr) { - // TODO: Conditionally include . const char *template = TEMPLATE( [name] @@ -51,11 +48,12 @@ static int atomAuthor(FILE *file, struct Address addr) { static char *atomEntryURL(const struct Envelope *envelope) { struct Variable vars[] = { + { "base", baseURL }, { "messageID", envelope->messageID }, { "type", "mbox" }, {0}, }; - return templateURL("/" PATH_MESSAGE, vars); + return templateURL("[base]/" PATH_MESSAGE, vars); } int atomEntryOpen(FILE *file, const struct Envelope *envelope) { @@ -64,7 +62,7 @@ int atomEntryOpen(FILE *file, const struct Envelope *envelope) { [id] [title] [updated] - + ); char *id = atomID(envelope); char updated[sizeof("0000-00-00T00:00:00Z")]; @@ -74,7 +72,6 @@ int atomEntryOpen(FILE *file, const struct Envelope *envelope) { { "id", id }, { "title", envelope->subject }, { "updated", updated }, - { "base", (atomBaseURL ? atomBaseURL : "") }, { "url", url }, {0}, }; @@ -105,39 +102,39 @@ int atomEntryClose(FILE *file) { return templateRender(file, TEMPLATE(), NULL, NULL); } -static char *atomFeedURL(const struct Envelope *envelope, const char *type) { +static char *atomThreadURL(const struct Envelope *envelope, const char *type) { struct Variable vars[] = { + { "base", baseURL }, { "messageID", envelope->messageID }, { "type", type }, {0}, }; - return templateURL("/" PATH_THREAD, vars); + return templateURL("[base]/" PATH_THREAD, vars); } -int atomFeedOpen(FILE *file, const struct Envelope *envelope) { +int atomThreadOpen(FILE *file, const struct Envelope *envelope) { const char *template = TEMPLATE( <[q]xml version="1.0" encoding="utf-8"[q]> [id] [title] [updated] - - - + + + ); char *id = atomID(envelope); time_t now = time(NULL); char updated[sizeof("0000-00-00T00:00:00Z")]; strftime(updated, sizeof(updated), "%FT%TZ", gmtime(&now)); - char *atom = atomFeedURL(envelope, "atom"); - char *html = atomFeedURL(envelope, "html"); - char *mbox = atomFeedURL(envelope, "mbox"); + char *atom = atomThreadURL(envelope, "atom"); + char *html = atomThreadURL(envelope, "html"); + char *mbox = atomThreadURL(envelope, "mbox"); struct Variable vars[] = { { "q", "?" }, { "id", id }, { "title", envelope->subject }, { "updated", updated }, - { "base", (atomBaseURL ? atomBaseURL : "") }, { "atom", atom }, { "html", html }, { "mbox", mbox }, @@ -153,6 +150,33 @@ int atomFeedOpen(FILE *file, const struct Envelope *envelope) { return error; } -int atomFeedClose(FILE *file) { +int atomThreadClose(FILE *file) { + return templateRender(file, TEMPLATE(), NULL, NULL); +} + +int atomIndexOpen(FILE *file) { + const char *template = TEMPLATE( + <[q]xml version="1.0" encoding="utf-8"[q]> + + [base] + [title] + [updated] + + + ); + time_t now = time(NULL); + char updated[sizeof("0000-00-00T00:00:00Z")]; + strftime(updated, sizeof(updated), "%FT%TZ", gmtime(&now)); + struct Variable vars[] = { + { "q", "?" }, + { "base", (baseURL ? baseURL : "") }, + { "title", baseTitle }, + { "updated", updated }, + {0}, + }; + return templateRender(file, template, vars, escapeXML); +} + +int atomIndexClose(FILE *file) { return templateRender(file, TEMPLATE(), NULL, NULL); } -- cgit 1.4.1