summary refs log tree commit diff
path: root/html.c
diff options
context:
space:
mode:
Diffstat (limited to 'html.c')
-rw-r--r--html.c94
1 files changed, 89 insertions, 5 deletions
diff --git a/html.c b/html.c
index 0d1ae11..8f349e5 100644
--- a/html.c
+++ b/html.c
@@ -393,12 +393,9 @@ int htmlSubthreadClose(FILE *file) {
 	return templateRender(file, TEMPLATE(</details>), NULL, NULL);
 }
 
-int htmlThreadClose(FILE *file) {
+static int htmlFooter(FILE *file) {
 	const char *template = TEMPLATE(
-		</main>
-		<footer>
-			generated <time datetime="[time]">[time]</time>
-		</footer>
+		<footer>generated <time datetime="[time]">[time]</time></footer>
 	);
 	time_t now = time(NULL);
 	char time[sizeof("0000-00-00T00:00:00Z")];
@@ -409,3 +406,90 @@ int htmlThreadClose(FILE *file) {
 	};
 	return templateRender(file, template, vars, escapeXML);
 }
+
+int htmlThreadClose(FILE *file) {
+	return 0
+		|| templateRender(file, TEMPLATE(</main>), NULL, NULL)
+		|| htmlFooter(file);
+}
+
+int htmlIndexHead(FILE *file) {
+	const char *template = TEMPLATE(
+		<!DOCTYPE html>
+		<meta charset="utf-8">
+		<title>[title]</title>
+		<link rel="alternate" type="application/atom+xml" href="index.atom">
+	);
+	struct Variable vars[] = {
+		{ "title", htmlTitle },
+		{0},
+	};
+	return templateRender(file, template, vars, escapeXML);
+}
+
+int htmlIndexOpen(FILE *file) {
+	const char *template = TEMPLATE(
+		<header class="index">
+			<h1>[title]</h1>
+			<nav>
+				<ul>
+					<li><a href="index.atom">follow</a></li>
+				</ul>
+			</nav>
+		</header>
+		<main class="index">
+			<ol>
+	);
+	struct Variable vars[] = {
+		{ "title", htmlTitle },
+		{0},
+	};
+	return templateRender(file, template, vars, escapeXML);
+}
+
+static char *htmlIndexURL(const struct Envelope *envelope) {
+	struct Variable vars[] = {
+		{ "messageID", envelope->messageID },
+		{ "type", "html" },
+		{0},
+	};
+	return templateURL(PATH_THREAD, vars);
+}
+
+int htmlIndexThread(
+	FILE *file, const struct Envelope *envelope, struct List thread
+) {
+	const char *template = TEMPLATE(
+		<li>
+			<h2 class="subject"><a href="[url]">[subject]</a></h2>
+			<address class="from">[from]</address>
+			<time datetime="[utc]">[date]</time>
+			<data class="replies" value="[replies]">[replies] repl[ies]</data>
+		</li>
+	);
+	char *url = htmlIndexURL(envelope);
+	char utc[sizeof("0000-00-00T00:00:00Z")];
+	strftime(utc, sizeof(utc), "%FT%TZ", gmtime(&envelope->time));
+	size_t count = threadCount(thread) - 1;
+	char replies[32];
+	snprintf(replies, sizeof(replies), "%zu", count);
+	struct Variable vars[] = {
+		{ "url", url },
+		{ "subject", envelope->subject },
+		{ "from", addressName(envelope->from) },
+		{ "utc", utc },
+		{ "date", envelope->date },
+		{ "replies", replies },
+		{ "ies", (count == 1 ? "y" : "ies") },
+		{0},
+	};
+	int error = templateRender(file, template, vars, escapeXML);
+	free(url);
+	return error;
+}
+
+int htmlIndexClose(FILE *file) {
+	return 0
+		|| templateRender(file, TEMPLATE(</ol></main>), NULL, NULL)
+		|| htmlFooter(file);
+}