summary refs log tree commit diff
path: root/atom.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 /atom.c
parentGenerate XHTML content in Atom entries (diff)
downloadbubger-7953ea0aef6d6d7110c95f368c07c1ac8b6223b8.tar.gz
bubger-7953ea0aef6d6d7110c95f368c07c1ac8b6223b8.zip
Generate index.atom
Diffstat (limited to '')
-rw-r--r--atom.c58
1 files changed, 41 insertions, 17 deletions
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 <email>.
 	const char *template = TEMPLATE(
 		<author>
 			<name>[name]</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>[id]</id>
 		<title>[title]</title>
 		<updated>[updated]</updated>
-		<link rel="alternate" type="application/mbox" href="[base][url]"/>
+		<link rel="alternate" type="application/mbox" href="[url]"/>
 	);
 	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(</entry>), 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]>
 		<feed xmlns="http://www.w3.org/2005/Atom">
 		<id>[id]</id>
 		<title>[title]</title>
 		<updated>[updated]</updated>
-		<link rel="self" href="[base][atom]"/>
-		<link rel="alternate" type="text/html" href="[base][html]"/>
-		<link rel="alternate" type="application/mbox" href="[base][mbox]"/>
+		<link rel="self" href="[atom]"/>
+		<link rel="alternate" type="text/html" href="[html]"/>
+		<link rel="alternate" type="application/mbox" href="[mbox]"/>
 	);
 	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(</feed>), NULL, NULL);
+}
+
+int atomIndexOpen(FILE *file) {
+	const char *template = TEMPLATE(
+		<[q]xml version="1.0" encoding="utf-8"[q]>
+		<feed xmlns="http://www.w3.org/2005/Atom">
+		<id>[base]</id>
+		<title>[title]</title>
+		<updated>[updated]</updated>
+		<link rel="self" href="[base]/index.atom"/>
+		<link rel="alternate" type="text/html" href="[base]/index.html"/>
+	);
+	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(</feed>), NULL, NULL);
 }