summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--archive.c4
-rw-r--r--archive.h1
-rw-r--r--bubger.17
-rw-r--r--html.c68
4 files changed, 50 insertions, 30 deletions
diff --git a/archive.c b/archive.c
index ca2914f..d6cc74c 100644
--- a/archive.c
+++ b/archive.c
@@ -32,6 +32,7 @@
 const char *baseURL = "";
 const char *baseTitle;
 const char *baseAddress;
+const char *baseSubscribe;
 
 static uint32_t uidRead(const char *path) {
 	FILE *file = fopen(path, "r");
@@ -75,12 +76,13 @@ int main(int argc, char *argv[]) {
 	const char *algo = "REFERENCES";
 	const char *search = "ALL";
 
-	for (int opt; 0 < (opt = getopt(argc, argv, "C:a:h:m:p:qs:t:u:vw:"));) {
+	for (int opt; 0 < (opt = getopt(argc, argv, "C:S:a:h:m:p:qs:t:u:vw:"));) {
 		switch (opt) {
 			break; case 'C': {
 				int error = chdir(optarg);
 				if (error) err(EX_NOINPUT, "%s", optarg);
 			}
+			break; case 'S': baseSubscribe = optarg;
 			break; case 'a': algo = optarg;
 			break; case 'h': concatHead = optarg;
 			break; case 'm': baseAddress = optarg;
diff --git a/archive.h b/archive.h
index 8d55328..5b7b134 100644
--- a/archive.h
+++ b/archive.h
@@ -183,6 +183,7 @@ char *templateURL(const char *template, const struct Variable vars[]);
 extern const char *baseURL;
 extern const char *baseTitle;
 extern const char *baseAddress;
+extern const char *baseSubscribe;
 
 #define MBOX_HEADERS \
 	"Date Subject From Sender Reply-To To Cc Bcc " \
diff --git a/bubger.1 b/bubger.1
index b626f6c..230adf1 100644
--- a/bubger.1
+++ b/bubger.1
@@ -1,4 +1,4 @@
-.Dd April 26, 2020
+.Dd April 30, 2020
 .Dt BUBGER 1
 .Os
 .
@@ -10,6 +10,7 @@
 .Nm
 .Op Fl qv
 .Op Fl C Ar path
+.Op Fl S Ar url
 .Op Fl a Ar algo
 .Op Fl h Ar head
 .Op Fl m Ar addr
@@ -38,6 +39,10 @@ Change directory to
 .Ar path
 before reading and writing files.
 .
+.It Fl S Ar url
+Add a subscribe link
+to the index page navigation.
+.
 .It Fl a Ar algo
 Set the threading algorithm to one of
 .Sy ORDEREDSUBJECT
diff --git a/html.c b/html.c
index 3cc740c..24cdf1a 100644
--- a/html.c
+++ b/html.c
@@ -109,31 +109,31 @@ static char *htmlMbox(const char *messageID) {
 	return templateURL("../" PATH_MESSAGE, vars);
 }
 
+static int
+htmlNavItem(FILE *file, const char *name, const char *base, const char *url) {
+	const char *template = TEMPLATE(
+		<li><a href="[base][url]">[name]</a></li>
+	);
+	struct Variable vars[] = {
+		{ "name", name },
+		{ "base", base },
+		{ "url", url },
+		{0},
+	};
+	return templateRender(file, template, vars, escapeXML);
+}
+
 int htmlMessageNav(FILE *file, const struct Envelope *envelope) {
 	int error = templateRender(file, TEMPLATE(<nav><ul>), NULL, NULL);
 	if (error) return error;
 	if (envelope->inReplyTo) {
-		const char *template = TEMPLATE(
-			<li><a href="[fragment]">parent</a></li>
-		);
 		char *fragment = htmlFragment(envelope->inReplyTo);
-		struct Variable vars[] = {
-			{ "fragment", fragment },
-			{0},
-		};
-		error = templateRender(file, template, vars, escapeXML);
+		error = htmlNavItem(file, "parent", "", fragment);
 		free(fragment);
 		if (error) return error;
 	}
-	const char *template = TEMPLATE(
-		<li><a href="[mbox]">download</a></li>
-	);
 	char *mbox = htmlMbox(envelope->messageID);
-	struct Variable vars[] = {
-		{ "mbox", mbox },
-		{0},
-	};
-	error = templateRender(file, template, vars, escapeXML);
+	error = htmlNavItem(file, "download", "", mbox);
 	free(mbox);
 	if (error) return error;
 	return templateRender(file, TEMPLATE(</ul></nav>), NULL, NULL);
@@ -505,26 +505,38 @@ int htmlIndexHead(FILE *file) {
 	return templateRender(file, template, vars, escapeXML);
 }
 
+static int htmlIndexNav(FILE *file) {
+	int error = 0
+		|| templateRender(file, TEMPLATE(<nav><ul>), NULL, NULL)
+		|| htmlNavItem(file, "follow", "", "index.atom");
+	if (error) return error;
+	if (baseSubscribe) {
+		error = htmlNavItem(file, "subscribe", "", baseSubscribe);
+		if (error) return error;
+	}
+	return 0
+		|| htmlNavItem(file, "write", "mailto:", baseAddress)
+		|| templateRender(file, TEMPLATE(</ul></nav>), NULL, NULL);
+}
+
 int htmlIndexOpen(FILE *file) {
-	const char *template = TEMPLATE(
+	const char *head = TEMPLATE(
 		<header class="index">
 			<h1>[title]</h1>
-			<nav>
-				<ul>
-					<li><a href="index.atom">follow</a></li>
-					<li><a href="mailto:[addr]">write</a></li>
-				</ul>
-			</nav>
-		</header>
-		<main class="index">
-			<ol>
 	);
 	struct Variable vars[] = {
 		{ "title", baseTitle },
-		{ "addr", baseAddress },
 		{0},
 	};
-	return templateRender(file, template, vars, escapeXML);
+	const char *tail = TEMPLATE(
+		</header>
+		<main class="index">
+			<ol>
+	);
+	return 0
+		|| templateRender(file, head, vars, escapeXML)
+		|| htmlIndexNav(file)
+		|| templateRender(file, tail, NULL, NULL);
 }
 
 static char *htmlIndexURL(const struct Envelope *envelope) {